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

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

other = script.Parent.Parent.TextButton
script.Parent.MouseButton1Click:Connect(function()
	wait(.23)
	other.Text = other.Text -2344
end)

1 comment

0

Use an if statement to check if the money is in the negatives. If it is, round back up to zero.!

1 answer

✓ Accepted answer

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)

3 comments

0

The first script will error because strings don't have changed event

0

Why does no one ever upvote? Me need the Educator rank D:

0

Fixed what incapaz was talking about

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