Hello, I am trying to make a "Kills" leaderstat where someone kills another player then they get + 1 on their Kills value. Whenever I test the script it gives me the error:
attempt to index local 'plr' (a nil value)
Here is my code, using a server script in the players character.
humanoid = script.Parent:FindFirstChild("Humanoid") --Gets the local players humanoid Torso = script.Parent:FindFirstChild("Torso") --Gets the local players torso Torso.Touched:connect(function(hit) --If statements to check if hit.Parent is the sword: "ATK" and the players health is 0 if not hit.Parent:FindFirstChild("ATK") then return end if not humanoid.Health == 0 then return end local char = hit.Parent.Parent --Gets the swords character local plr = game.Players:GetPlayerFromCharacter(char) --Gets the player with the sword plr.leaderstats.Kills = plr.leaderstats.Kills + 1 --Adds 1 to the value, this is where I get the error end)
I'm not sure why I am getting this error and if you could tell me that would be great thanks!