I’m working on a game where a player has a certain amount of “Kills” in their leaderstats (shown in game). The leaderstats work fine, but for some reason when they kill another player, their “Kills” value doesn’t increase like the script tells it to. Here’s the code, located in a Script in ServerScriptService:
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = leaderstats
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
local player = tag.Value
player.leaderstats.Kills.value = player.leaderstats.Kills.Value + 1
end
end)
end)
I’ve seen this same script so many times. Did you get it from a tutorial? When did you create the “creator” value in the Humanoid?
Also change that code to
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = leaderstats
plr.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag ~= nil then
local player = tag.Value
player.leaderstats.Kills.value = player.leaderstats.Kills.Value + 1
end
end)
end)
Thanks for your inputs, I used a combination of your solutions and it worked!
The code:
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local kills = Instance.new("IntValue")
kills.Name = "Kills"
kills.Parent = leaderstats
plr.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
local tag = character.Humanoid:FindFirstChild("creator")
if tag then
local player = tag.Value
player.leaderstats.Kills.value = player.leaderstats.Kills.Value + 1
end
end)
end)
Nice! Please press the Solution button on this post that I’m replying to and also edit the post to provide the code for anyone else that is having this problem.
All his script did was change the variable for player. I think mine was the one that solved the problem. His also helped by creating 2 different variables. You should have named the other player variable killer or something else.