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

how does one set a limit on int values?

ive made a hunger script and whenever i eat something the value goes over 100 and i want the cap to be 100

2 answers

You can do this easily with a simple script that goes something like this:

local hunger = script.Parent --change 'script.Parent' to your hunger value

--if for some reason their hunger is above 100 when they join
if hunger.Value > 100 then --if the value is over 100 then
	hunger.Value = 100 --changes the value to 100
end

--fires when the player's hunger is changed and checks to see if its above 100
hunger.Changed:Connect(function()
	if hunger.Value > 100 then --if the value is over 100 then
		hunger.Value = 100 --changes the value to 100
	end
end)
local intValue = YourIntValue -- Put the path to your intValue

If intValue.Value > 100 then
intValue.Value = 100
end

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