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

How to stop a int value going above 100?

Asked by
kaemi 21
6 years ago
Edited 6 years ago

Hello there i was making a hunger script but then i noticed that the hunger meter can go to above 100% how i can stop this number going up? this should be in line 25 to 28

local HG = script.Parent
local Text = HG:WaitForChild("Back"):WaitForChild("Text")
local Plr = game.Players.LocalPlayer

repeat wait() until Plr.Character

local Hum = Plr.Character:WaitForChild("Humanoid")
local MaxHunger = 100
local DecreaseRate = 3 -- 8 seconds = -1 hunger
local HungerValue

if Plr:FindFirstChild("HungerVal") then
    HungerValue = Plr.HungerVal
    HungerValue.Value = MaxHunger
else
    Instance.new("IntValue", Plr).Name = "HungerVal"
    Plr.HungerVal.Value = MaxHunger
    HungerValue = Plr.HungerVal 
end

HungerValue.Changed:connect(function()
    Text:TweenSize(UDim2.new(HungerValue.Value/MaxHunger,0, 1,0), "Out", "Linear", .2, true)
end)

while true do
    if HungerValue.Value >= 100 then
        HungerValue.Value = 100
    end

while wait(DecreaseRate) do
    if HungerValue.Value - 1 >= 0 then
        HungerValue.Value = HungerValue.Value - 1
    end

    if HungerValue.Value == 0 then
        repeat wait(1)
            Hum.Health = Hum.Health - 2
        until HungerValue.Value > 0 or Hum.Health <= 0
    end
end
end
0
I'm confused do you have a gui for how much hunger you have? KiwiAviation 0 — 6y
0
yeah i have the gui! kaemi 21 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Make it so that if the value is over the limit, just set the value to the limit every time it tries to.

0
How? kaemi 21 — 6y
0
k got it kaemi 21 — 6y
0
Cool tobyjing2005 107 — 6y
Ad

Answer this question