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

Gui incremental add/subtract script help?

I have two buttons and a number, and I want the top button to increase the number one, and the bottom one to subtract the number from one.

Is this a correct script? If not please help me!

startingNumber = 0
offset = 1

script.Parent.MouseButton1Click:Connect(function()
	startingNumber = offset+1
end)

1 answer

✓ Accepted answer

As it stands, you're setting startingNumber to the variable offset with 1 added to it. This means that startingNumber will only ever be 2, as you never change the offset. To fix this, you might want to add 1 to startingNumber itself.

As well as this, you have to add both buttons you want to detect click for into the script. For example, if the local script was inside a frame with two gui buttons called IncreaseButton and DecreaseButton, you could do something like this:

local startingNumber = 0
local increment = 1

script.Parent.IncreaseButton.MouseButton1Click:Connect(function()
	startingNumber = startingNumber + increment
	print(startingNumber)
end)
script.Parent.DecreaseButton.MouseButton1Click:Connect(function()
	startingNumber = startingNumber - increment
	print(startingNumber)
end)

If you were looking to limit the extent that the number can range from, you could look into using math.clamp.

1 comment

0

Thank you so much!

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