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

how does one set a limit on int values?

Asked by 3 years ago

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

Log in to vote
1
Answered by
zane21225 243 Moderation Voter
3 years ago

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)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago
local intValue = YourIntValue -- Put the path to your intValue

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

Answer this question