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)
Hopefully this works, I checked it out and it looks like you were trying to reference Players.LocalPlayer which only works in LocalScripts, meaning you can't use it in a normal script. Since you already put player in the () on the Players.PlayerAdded you only had to do local leaderstats = player.leaderstats.
Hopefully it works, if it doesn't work make sure you have made it in a normal script. Good luck on your FFA game!
local Players = game.Players Players.PlayerAdded:Connect(function(player) wait(1) local leaderstats = player.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)