Roblox Leaderstats aren't updating correctly. When told to update leaderstats, it sometimes doesn't update, and other times, it only updates once. Code is below:
game.ReplicatedStorage.sleep.OnServerEvent:Connect(function(plr)
local en = plr.leaderstats.Energy
en.Value += 1
print(en.value)
wait()
local speed = 5.07 * ((en.Value / 10) + 1)
plr.Character:WaitForChild("Humanoid").WalkSpeed = speed
print(speed)
end)
On times it doesn't update, the print(en.value)
says 1 while the leaderstat stays as 0.
When leaderstat only updates once, the print only updates once as well.
Edit: The leaderstat was defined/created in a previous script.
I completely forgot to answer this, but I am using +=, you would assume it would add to the current amount as the hint says, but it doesn't
Old Code: en.Value += 1
What I do now: en.Value = en.Value + 1