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

How do I set a maximum value for an intvalue?

Does anyone know how to set a max value for an intvalue? Because when I tried my script, it didn’t work here’s what I had, and I the folder is leaderstats and the coins are coins, VSpace is the max value

plr.leaderstats.coins.Changed:Connect(function()
local max = VSpace.Value
if coins.Value > max then
coins.Value = max
end
end)

That’s what I had but whenever I collect a coin, it automatically sets the coins value to the max how do I fix this?

2 comments

0

you could use math.min to clamp it down on a certain value

0

coins.Value = math.min(coins.Value,MaxValue)

2 answers

So would this be right theking28989987?

plr.leaderstats,coins.Changed:Connect(function()
local max = VSpace.Value
if coins.Value > max then
coins.Value = math.min(coins.Value,max)

Is that right?

1 comment

0

you dont need the if statement

plr.leaderstats.coins.Changed:Connect(function()
local max = VSpace.Value
if coins.Value >= max+1 then
coins.Value = max
end
end)

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