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

Gui incremental add/subtract script help?

Asked by
tek_o 56
5 years ago

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

Log in to vote
2
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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.

0
Thank you so much! tek_o 56 — 5y
Ad

Answer this question