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

How would I minus a number by 1000 instead of reseting it to 2000? [closed]

Asked by 5 years ago
Edited 5 years ago

This question already has an answer here:

How do I make a number minus limit?

````So I am trying to make a script that allows the player to minus the number and add the number but there is a minimum number. I have already figured out how to make a limit but when I minus the number it resets to 2000 and when I add the number it goes back to what it was on when I added it.

Add script:

local z = Instance.new("DoubleConstrainedValue",script.Parent)
local vz = script.Parent.Parent.Variable2

z.MinValue = 2000
z.MaxValue = math.huge

function onButtonClicked()
z.Value = z.Value + 1000
vz.Text="z:("..tostring(z.Value)..")"
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

Minus Script:

local z = Instance.new("DoubleConstrainedValue",script.Parent)
local vz = script.Parent.Parent.Variable2

z.MinValue = 2000
z.MaxValue = math.huge

function onButtonClicked()
z.Value = z.Value - 1000
vz.Text="z:("..tostring(z.Value)..")"
end

script.Parent.MouseButton1Click:connect(onButtonClicked)

Please reply

0
DoubleConstrainedValue's are deprecated. Why not just use a normal NumberValue, and just use math.clamp to constrain the value in between 2 numbers? It works like so: math.clamp(num, min, max) User#24403 69 — 5y
0
Where would I put it HiHowAreYah5 19 — 5y
0
Yes, use math.clamp. You want to assign it to vz like you did with z.Value. pidgey 548 — 5y

Marked as Duplicate by Mr_Unlucky, pidgey, and theking48989987

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
qChaos 86
5 years ago

The reason seems to be because the Minimum Value is staying at 2000, but you are setting the value to below that so it's correcting itself, try setting the minimum value to minus 1000 as well.

0
That didn't work HiHowAreYah5 19 — 5y
Ad