I'm trying to add a button which sets the death value from the leaderstats script to 0. Everything works fine, the deaths count up when the player dies, and the deaths get a reset when pressing the button. But when I die again after resetting, the value continues from where it left off (ex: if i had 5 deaths then hit the reset button, it would be 0 until I die again, where it becomes 6 instead of 1).
Does anyone know what the issue is? I'm very new to scripting, so sorry for my lack of vocabulary or if the answer is pretty obvious.
My leaderstats script:
game:GetService('Players').PlayerAdded:connect(function(player)
player.CharacterAdded:connect(function(character)
character:WaitForChild("Humanoid").Died:connect(function()
print(player.Name .. " has died!") --check
player.leaderstats.Deaths.Value = player.leaderstats.Deaths.Value + 1 --adds death on death
end)
end)
end)
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Model", player)
leaderstats.Name = "leaderstats"
local score = Instance.new("IntValue", leaderstats)
score.Name = "Deaths"
score.Value = 0
end)
This thing works fine in the game, notable things are that deaths starts at 0, and increase by one on death.
I have a localscript that resets the death value in the textbutton
Player = game.Players.LocalPlayer
script.Parent.MouseButton1Up:connect(function()
local index, stat
for index, stat in pairs(Player.leaderstats:GetChildren()) do
stat.Value = 0 --resets die
end
end)
(I plan on adding more stats which can be reset later, which is why it resets all leaderstats on the button press even though there is only one)

2 comments
2nd code chunk is from the localscript that resets the death value in the textbutton (that wasn't clear, sorry)
I am not sure about this but you could try change the local script to normal script (Note Localplayer doesn't work in normal script)