Adding To Numbers Using Script

So, I have been creating a game to practice scripting in Roblox Studio. I ran into an issue… Again… And I need some help. You see, I want to make it so that when you click a GUI text button, it adds 1 to a number on a text label. I don’t know if this is even possible, but if so, please tell me what I need to do as I am stuck. Thank you!

Here are some pictures…

image

image

image

1 Like

Are you using a GUI Button or a click detector?

I am using a GUI Text Button for it.

I am not completely sure that I understand. You have to know I have never really scripted that much before. Is there anything else you could do to explain that process? Sorry!

Here is a method you could try:

-- LocalScript inside of the TextButton

local label = -- path to your TextLabel inside of your SurfaceGui
local number = 0

script.Parent.MouseButton1Click:Connect(function()
    number += 1
    label.Text = number
end)

Replace the comment to reference your TextLabel inside of your SurfaceGui

2 Likes

It worked, but It added to the counter every time you pressed the button. Let me show you some more pictures.

Here are the two counters I need the GUI to communicate with.
image

Here is the location I need a part to go so that then when you click the GUI, it adds one to the counter.
image

And here is the script I have so far. I need some lines in there though to trigger the counter.
image

Do
local label = game.Workspace.Counter.SurfaceGui.TextLabel
local number = 0
local button = script.Parent.TextButton

button.MouseButton1Click:Connect(function()
number += 1
label.Text = (number)

If this doesn’t work, I am sorry.

It didn’t work, but it’s okay! I’ll find another way to get it up and running!

1 Like