Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

why doesn't this script work? [couldn't think of a better title]

wait(1)
print("FOUND IT")
if game.Players.LocalPlayer.leaderstats.Hunger.Value <= 10 then
	e = true
	print("1234")
	while e do
		wait(2)
		print("UGH")
	game.Players.LocalPlayer.Character.Humanoid.Health = game.Players.LocalPlayer.Character.Humanoid.Health - 10
	end
end

--[[if player.Character.Humanoid.Health <= 0 then
	e = false
	--]]

all this does is print found it. i changed my leaderstats hunger value to 1, and it didnt do anything. i've tried this in both server script and local script. lines 13-15 are in comments because i wanted to handle one problem at a time.

1 answer

✓ Accepted answer

It's because it will only run the code once, so it will only do everything you said once. You can put it in a loop so it checks "Hunger" more than just once but forever! Like this:

wait(1)
print("FOUND IT")

while wait(1) do -- the 1 can be changed to anything, it is how much it waits to repeat the loop in seconds, 1 would mean it would do this every second.
	
if game.Players.LocalPlayer.leaderstats.Hunger.Value <= 10 then
    e = true
    print("1234")
    while e do
        wait(2)
        print("UGH")
    game.Players.LocalPlayer.Character.Humanoid.Health = game.Players.LocalPlayer.Character.Humanoid.Health - 10
    end
end

end

--[[if player.Character.Humanoid.Health <= 0 then
    e = false
    --]]

2 comments

0

Why not just run it when the hunger changes?

0

wow, i didnt even think of a a loop when i typed that

This discussion is preserved as it was. New answers, comments, and votes are closed.