✓ Accepted answer
Because if statements only check a conditional one time, it is sub-optimal to use it for this type of purpose, where you need a consistent checking method to make sure the person gets a point when they die. Humanoids can have a listening event attached to them called Died which is called when a humanoid's health hits 0. Since the humanoid is refreshed with a new character, one humanoid listening event connection simply won't do. We will need to also call a function for every time a character is added, which will lead to a humanoid being added. What we get is something similar to your code with a slight change at the end.
game.Players.PlayerAdded:connect(function(plr)
local stats = Instance.new("Model", plr)
stats.Name = "leaderstats"
local WOs = Instance.new("IntValue", stats)
WOs.Name = "WOs"
WOs.Value = 0
plr.CharacterAdded:connect(function(chr)
chr:WaitForChild("Humanoid").Died:connect(function()
if WOs and WOs.Parent then
WOs.Value = WOs.Value+1
end
end)
end)
end)
Hope this helped, and if it did, please don't forget to upvote!
1 comment
You are not constantly checking if the value is zero, you should use the humanoid Died() event