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

I'm having some issues with my eating and starvation script. Any fixes?

Asked by 4 years ago
Edited 4 years ago

Hello everyone, I am making a roblox game that includes an eating, and starvation feature. My eating script is causing an error, also, the console is not showing any errors so im 100% sure that my code is just buggy. I will include the starvation script and the eating script Whenever I eat some food, the next time it goes to remove a bit of hunger, it removes WAY too much

Eating script:

food = "Food"
hunger = "Hunger"
script.Parent.MouseButton1Click:Connect(function()
    for i, v in pairs(game.Players:GetPlayers())do
        if v:FindFirstChild("leaderstats")then
            if v.leaderstats[food].Value == 0 then print("error") else
            if v.leaderstats[hunger].Value == 20 then print("error")
        else if v.leaderstats[hunger].Value + 5 > 20 then v.leaderstats[hunger].Value = 20 
            v.leaderstats[food].Value = v.leaderstats[food].Value - 1 else
                v.leaderstats[hunger].Value = v.leaderstats[hunger].Value + 5
                v.leaderstats[food].Value = v.leaderstats[food].Value - 1
                    end
                end
            end
        end
    end
end)

starvation script:

hunger = "Hunger"
while true do
    wait(0.000000001)
    for i,v in pairs(game.Players:GetPlayers())do
        if v:FindFirstChild("leaderstats")then
            if v.leaderstats[hunger].Value == 0 then v.Character.Humanoid.Health = 80
                wait(2)
                v.leaderstats[hunger].Value = 0
                v.Character.Humanoid.Health = 60
                wait(2)
                v.leaderstats[hunger].Value = 0
                v.Character.Humanoid.Health = 40
                wait(2)
                v.leaderstats[hunger].Value = 0
                v.Character.Humanoid.Health = 20
                wait(2)
                v.leaderstats[hunger].Value = 20
                v.Character.Humanoid.Health = 0
            end
        end
    end
end
0
If your only problem is that it removes too much, then just change the wait time for the next removal, or just change the number. You didnt state any other problems. SchwarzWalde -12 — 4y
0
Yeah, there should've any other errors, maybe some problems you don't like but they aren't errors. Torren_Mr 334 — 4y

Answer this question