How do I +1 a value of a IntValue when I press a Text Button?

How do I +1 a value of a IntValue when activating a TextButton? I thought you would write it like this…

script.Parent.Activated:Connect(function()
    value = value + 1
end)

but it wouldn’t work, any help appreciated :slight_smile:

Try use

script.Parent.MouseButton1Down:Connect(function()
    value += 1
end)

You’d need to reference the Value property of the intValue for it to add to its value

local intValue = your value

script.Parent.Activated:Connect(function()
    intValue.Value += 1
end)

Though since Guis usually use localscripts, if you want this to be server sided, you’d probably need to either make it it use a regular script or RemoteEvent

yep, thats what I was doing and It was erroring

Oh wait I read it wrong sorry, let me try it

Could you please tell us the error?

He said the error is that the value isn’t going up

When someone says “erroring” from what I have seen it usually means there is an error in the console.

Here:

local value = 0

script.Parent.MouseButton1Click:Connect(function()
	value += 1
	script.Parent.Text = "Value: "..value
end)

Works fine for me.

Business Builders - Roblox Studio (gyazo.com)

They can also add a debounce from your code, in case they don’t want the player who clicks the button to spam

local value = 0
local db = false

script.Parent.MouseButton1Click:Connect(function()
	if db == false then
		db = true
		value += 1
		script.Parent.Text = "Value: "..value
		db = false
	end
end)

or just use a wait()
(Also, sorry if the code is broken)

1 Like

you made a mistake here, the odd one

2 Likes

Thank you! I tend to write both db and debounce…

2 Likes