generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Figuring out if a player killed someone?

Previous Thread :: Next Thread 
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
13 Apr 2015 03:14 PM
I'm trying to make my own currency for my game that only rewards if you kill someone. How do I accomplish this? Here's the code so far (It is basically straight from the wiki)

local playerLeaderstats = {}
local player = game.Players.PlayerAdded:connect(player)

game.Players.PlayerAdded:connect(function(player)
playerLeaderstats[player] = {}
playerLeaderstats[player]["Money"] = 0
local leaderstats = Instance.new("Model")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local money = Instance.new("IntValue")
money.Name = "Ji!s"
money.Value = playerLeaderstats[player]["Jis"]
money.Parent = leaderstats
end)

while wait(5) do
for _,Player in pairs(game.Players:GetPlayers()) do
--We don't use the IntValue's value because an exploiter can modify it.
playerLeaderstats[player]["Money"] = playerLeaderstats[player]["Money"] + 1
if Player:FindFirstChild("leaderstats") then
Player.leaderstats.Money.Value = playerLeaderstats[player]["Money"]
end
end
end
Report Abuse
soniclover88888 is not online. soniclover88888
Joined: 01 Feb 2008
Total Posts: 6723
13 Apr 2015 03:14 PM
http://wiki.roblox.com/index.php?title=Died
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
13 Apr 2015 03:16 PM
@sonic
I know about that, how can I figure out if somebody actually killed the player? E.g. if I shoot the player the game knows I did it and rewards me points.
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
13 Apr 2015 03:20 PM
The 'traditional' method is to add a value to the person being attacked, and the value would have the attacker's name or the attacker itself. But the problem with this is that, it gets the player who last hits the person. This is what most people want, but the flaw is that, if the player is killed by an outside force or by itself, that last hitter would still get the credit.
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
13 Apr 2015 03:22 PM
You need to work with tags and stuff. You can look in the ROBLOX linked leaderboard for the leaderboard script and you also need to make your weapons have tags. It works by tagging a player when they are damaged by a weapon and when that player dies, it looks for a tag indicating the killer.
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
13 Apr 2015 03:22 PM
darn ninja
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
13 Apr 2015 03:23 PM
@Essence
I don't want to have to add on to my already existing weapons, and that sounds like a horrible way of doing it, so what is the non-traditional way?
Report Abuse
soniclover88888 is not online. soniclover88888
Joined: 01 Feb 2008
Total Posts: 6723
13 Apr 2015 03:24 PM
"I don't want to have to add on to my already existing weapons"

You can do this very easily with a bool value that switches on when it hits a player and then switches off when the same player is hit by someone else.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
13 Apr 2015 03:25 PM
1. Super complex system that figures out if someone killed someone else.

2. Standard method of tagging the humanoid.

http://codepad.org/5H4aio5u

That is a pretty much shortened version of roblox's linked leaderboard, it's from my current project.


I script -~ chimmihc
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
13 Apr 2015 03:26 PM
Well, you could use a local script that gets the value of 'killer' for each player instead. I think you can use remote events to fire a server event from the client. Not sure though because I never really bothered to learn about remove events. Hopefully someone else comes to help.
Report Abuse
rayk999 is not online. rayk999
Joined: 18 Feb 2011
Total Posts: 4705
13 Apr 2015 03:27 PM
When I was a noob, I tried to make a leaderboard that would do sort of the same thing except also attach the amount of damage they had dealt along with the name. The leaderboard would take the person who did the most damage and added a kill to them
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
13 Apr 2015 03:27 PM
@sonic
i'm interested, do you mean have it so when a player is killed it goes to true?
Report Abuse
soniclover88888 is not online. soniclover88888
Joined: 01 Feb 2008
Total Posts: 6723
13 Apr 2015 03:30 PM
Not a boolvalue, I'm sorry.
What I meant is have two values stored; the name of the joined player and a blank value. Once the player gets hit, have the blank value display the name of the person that hit you (by reading the named value of the other player). Once you die, have a function run that displays the name of the character that was killed and the name of the killer (assuming you want it to run for everyone).
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
13 Apr 2015 03:32 PM
local script
-------------

local last_hitter = nil
local char = game.Players.LocalPlayer.Character
local alive = true

for i,v in pairs(char) do
if v:IsA("Part") and alive then
v.Touched:connect(function(h)
local h = h
if game.Players:GetPlayerFromCharacter(h.Parent) then
last_hitter = h.Parent.Name
end
end)
end
end

char.Humanoid.Died:connect(function()
alive = false
-- Your point giving code here, last_hitter being the killer.
end)
Report Abuse
soniclover88888 is not online. soniclover88888
Joined: 01 Feb 2008
Total Posts: 6723
13 Apr 2015 03:35 PM
If you want to add an "assist" value, you could do math for damage calculated by each player, let the player who does the final shot get the kill and then give the other player(s) points depending on how much damage they did. I don't know how it's done, but Phantom Forces and Mad Paintball do it, so I know it's possible.
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
13 Apr 2015 03:35 PM
last_hitter = h.Parent.Name

change that to

last_hitter = h.Parent

since you would probably want the player, not its name
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
13 Apr 2015 03:37 PM
"and alive then"
I don't think that will work.
@Chim Thanks for showing me that, can I use it?
Report Abuse
Goulstem is not online. Goulstem
Joined: 04 Jul 2012
Total Posts: 7177
13 Apr 2015 03:37 PM
Tag your weapons mate
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
13 Apr 2015 03:38 PM
alive = true

it's basically saying 'and true then'
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
13 Apr 2015 03:38 PM
If you want.


I script -~ chimmihc
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
13 Apr 2015 03:39 PM
@Chim
That goes inside of a server script in workspace or in my weapon?
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
13 Apr 2015 03:40 PM
Server script -- ServerScriptService


I script -~ chimmihc
Report Abuse
Klink45 is not online. Klink45
Joined: 06 Jun 2011
Total Posts: 26054
13 Apr 2015 03:45 PM
Thanks Chim, but it did not work for me. So how do I properly "tag" a weapon?
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
13 Apr 2015 03:52 PM
Come to my current place.


I script -~ chimmihc
Report Abuse
iiEssence is not online. iiEssence
Joined: 18 Jun 2014
Total Posts: 3467
13 Apr 2015 03:53 PM
You said you didn't want to use 'tags' and I gave you a solution. You are completely ignoring a solution that's already given to you because you don't understand a part of a script, which, by the way, I provided an explanation for.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image