I tried to make a system that when the leaderstats reaches zero, the player takes damage. I've tried lots of methods, bit it still don't work
local Players = game:GetService("Players") local plr = Players.LocalPlayer local PlayerMoneyValue = plr.leaderstats.Reality.Value while true do wait(0.5) if PlayerMoneyValue < 1 then plr.Parent.Humanoid:Takedamage(10) end end
[EDIT: corrected humanoid damage] By doing this:
local PlayerMoneyValue = plr.leaderstats.Reality.Value
You are only saving INITIAL money value to PlayerMoneyValue
variable. To make this script work, you need to keep a reference to the intValue
object, like this:
local PlayerMoneyValue = plr.leaderstats.Reality
Only then You can get the CURRENT money value inside the loop. Notice how I added .Value
here. This way you make script to recheck the amount on each iteration:
while true do wait(0.5) if PlayerMoneyValue.Value < 1 then local char = plr.Character if not char then continue end char.Humanoid:Takedamage(10) end end
I hope this helps.