Hello! I am working on a FFA game and when I wanted to make a kill counter, it doesn't work and I don't get what's happening.
One thing I did notice is that in the output it said that I attempted to index nil with the "leaderstats" folder.
I'd be happy to find a solution from your answers! Thanks!
Code used:
local Players = game.Players
Players.PlayerAdded:Connect(function(player)
wait(1)
local leaderstats = Players.LocalPlayer.leaderstats -- This is the line that the error in the output mentioned
local kills = leaderstats.Kills
player.CharacterAdded:Connect(function(character)
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Died:Connect(function()
for i, child in pairs(humanoid:GetChildren()) do
if child:IsA('ObjectValue') and child.Value and child.Value:IsA("Player") then
local killer = child.Value
if killer:FindFirstChild("leaderstats") and killer.leaderstats:FindFirstChild("Kills") then
killer.leaderstats.Kills.Value = killer.leaderstats.Kills.Value + 1
end
end
end
end)
end
end)
end)

2 comments
It doesn't seem to work, and as long as I changed the "ObjectValue" to "IntValue" at line 12 (because I was using an IntValue for the kill count) still doesn't seem to work and there are no errors printed into output?
hm. could you maby try to make the script in another way?