Help adding in a function

Hi! I need help adding 1 value to a Surface Gui I have in a loop. I thought that this would just wait 1 second, then add 1 value to the already existing value over and over again, but I was wrong. Any help would be greatly appreciated!

game.Workspace.Buttons.Dropper1Button.Touched:Connect(function(Add)
	script.Parent.Text = "0"
	wait(1)
	script.Parent.Text = "0" + 1
end)
1 Like

You can’t combine a number with a string, but tostring() and tonumber() exists. For example,

local debounce = false
local current = 0
game.Workspace.Buttons.Dropper1Button.Touched:Connect(function(Add)
if not debounce then debounce = true
	script.Parent.Text = current
	task.wait(1)
	script.Parent.Text = tostring(current += 1)
        current += 1
        debounce = false
end
end)

tostring() converts numbers into a string.
tonumber() converts a string into a number. (if it contains numbers of course)
Adding on to this, you can add a debounce so it wont bug as much.

2 Likes

this works

game.Workspace.Buttons.Dropper1Button.Touched:Connect(function(Add)
	script.Parent.Text = tostring(script.Parent.Text + 1)
end)
2 Likes

Sorry for the late reply, I will try both of theses, thank you both for your advice. @nds_w