In my game, I planned out that each time someone kills another person, they would gain a better weapon. I would like to understand the basics of tracking players and their kills.
How would you track a player kill?
1 answer
You would have somewhere storing each players deaths and kills. I usually use a table in a server-side script somewhere. Something like:
local Stats = {}
Then when a player joins simply add another table that is the players name such as:
game.Players.PlayerAdded:Connect(function(Player)
Stats[Player.Name] = {}
Stats[Player.Name]['Kills'] = 0
Stats[Player.Name]['Deaths'] = 0
end)
Same for when they leave:
game.Players.PlayerRemoving:Connect(function(Player)
--Any save code here
Stats[Player.Name] = nil
end)
Tracking player kills would go something like this. If you were going to have the weapon be a gun, each bullet should have a value of the person who shot it. Then if that player dies, grab the value and increment that players kills by 1. So a little bit of pseudo code would be like this:
local Event = someEventFiredWhenBulletSent
Event.OnServerEvent:Connect(function(Player, Bullet)
--Draw bullet here, get humanoid, take damage, etc, see the attached link at bottom of answer
if humanoid.Health <= 0 then
--Give person shot a point towards death
local Victim = game.Players:GetPlayerFromCharacter(humanoid.Parent).Name
Stats[Victim]['Deaths'] = Stats[Victim]['Deaths'] + 1
--Now give the shooter a point for killing
Stats[Player.Name]['Kills'] = Stats[Player.Name]['Kills'] + 1
end
end)
See: http://wiki.roblox.com/index.php?title=Making_a_ray-casting_laser_gun as a good example for drawing rays, getting the person who was shot humanoid.
1 comment
Oh thanks, I get it now.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
First off, don't put your description of your problem in a code block. You use code blocks to show your scripts.
He didn't. Tabbing your sentences does this by itself.