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

How to stop a int value going above 100?

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

2 comments

0

I'm confused do you have a gui for how much hunger you have?

0

yeah i have the gui!

1 answer

✓ Accepted answer

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

3 comments

0

How?

0

k got it

0

Cool

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