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

How do I set a maximum value for an intvalue?

Asked by 5 years ago

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?

0
you could use math.min to clamp it down on a certain value theking48989987 2147 — 5y
0
coins.Value = math.min(coins.Value,MaxValue) theking48989987 2147 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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?

0
you dont need the if statement theking48989987 2147 — 5y
Ad
Log in to vote
0
Answered by
gloveshun 119
5 years ago
plr.leaderstats.coins.Changed:Connect(function()
local max = VSpace.Value
if coins.Value >= max+1 then
coins.Value = max
end
end)

Answer this question