Hello, this might be a bit confusing because of the way I have certain things named, so read carefully.
I have a script where whenever someone gets a kill, their leaderstats for “kills” goes up by 1. And their deaths go up by 2. (I wanted to rename this to points but when I did it stopped working so I am just keeping it like this for now.)
I then have it where whenever they die, their deaths go back to 0.
The problem is that it only works with 1 player, both players can kill each other, and the script will work fine except for when 1 of the players die, it does not set their deaths to 0. This only happens with one of the players, as when you kill the other player it does get set back to 0.
Hm, alright the first thing I notice are the variable warnings, you should be a local variable instead
Also, why are you changing the Deaths.Value to 0? (Aka subtracting the Deaths.Value from itself)
Next, please don’t use the second parameter when using Instance.new(), it’s slower
This should work, but I’m not exact if it will:
game.Players.PlayerAdded:Connect(function(Player)
local Stat = Instance.new("IntValue")
Stat.Name = "leaderstats"
Stat.Parent = Player
local Kills = Instance.new("IntValue")
Kills.Name = "Kills"
Kills.Parent = Stat
local Deaths = Instance.new("IntValue")
Deaths.Name = "Deaths"
Deaths.Parent = Stat
if Use_DP then --This is either not a valid variable or you didn't define it right, not enough information
loadStat(player, "Kills", Kills)
loadStat(player, "Deaths", Deaths)
end
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:WaitForChild("Humanoid")
Humanoid.Died:Connect(function()
Deaths.Value = 0
local Cre = Humanoid:FindFirstChild("creator")
if Cre and Cre.Value then
local leaderstats = Cre.Value:FindFirstChild("leaderstats")
if leaderstats then
leaderstats.Kills.Value += 1
leaderstats.Deaths.Value += 2 --Wait why doe
else
Kills.Value = Kills.Value
end
if Use_DP then
saveStat(Cre.Value, leaderstats.Kills.Value, "Kills")
saveStat(Player, Kills.Value, "Kills")
end
end
end)
end)
end)
For some reason thats not changing any of the leader stats. The reason I was wanting deaths to go up by 2 whenever you get a kill is because I am gonna rename it to points for example. (Sorry I know that was confusing). I then wanted the “points” to reset back to 0 once you die. I might be doing something wrong but when using that code nothing happens when you get a kill or die.
They still don’t change. But also, the Use_DP variable was something that was defined earlier in the code, but I don’t need it. It can be removed. I don’t think that would make a difference though as I removed it and it still didn’t work, unless I did something wrong.