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

i have been tying to make a gui shop thou the money keeps going in the negatives. how do i fix??

Asked by 5 years ago
other = script.Parent.Parent.TextButton
script.Parent.MouseButton1Click:Connect(function()
    wait(.23)
    other.Text = other.Text -2344
end)
0
Use an if statement to check if the money is in the negatives. If it is, round back up to zero.! User#19524 175 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

As Incapaz said, use and if statement to check if the Value is below zero, and if it is, make it 0. Don't think you can do this with TextButton though, as those can have any Strings, Floats, or Booleans, so I would recommend putting a Value somewhere, and have it update to "other.Text"'s Value whenever it is changed.To do this, you could make an IntValue, make a script, and do something like this:

UpdateValue:

local other = --Reference the "other TextButton" from the previous script here.
local CurrentOther = --Reference the IntValue here
other.Changed:Connect(function()
CurrentOther.Value = other.Text
end)

To add on to your current code to make sure it doesn't go in the negatives:

local other = script.Parent.Parent.TextButton
local CurrentOther= --Reference your IntValue here.
script.Parent.MouseButton1Click:Connect(function()
wait(23)
other.Text = other.Text - 2344
if CurrentOther.Value < 0 then
CurrentOther.Value = 0
other.Text = 0
end)
0
The first script will error because strings don't have changed event User#19524 175 — 5y
0
Why does no one ever upvote? Me need the Educator rank D: SBlankthorn 329 — 5y
0
Fixed what incapaz was talking about SBlankthorn 329 — 5y
Ad

Answer this question