Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
theCJarmy7 1293 Moderation Voter
8 years ago
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

Log in to vote
1
Answered by
lucas4114 607 Moderation Voter
8 years ago

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
    --]]
0
Why not just run it when the hunger changes? Pyrondon 2089 — 8y
0
wow, i didnt even think of a a loop when i typed that theCJarmy7 1293 — 8y
Ad

Answer this question