My tapping button isnt going up 1 in the counter when i click it

Oh oops, I forgot to include .Frame2.counter

local counter = script.Parent.Parent:WaitForChild("ScreenGui2").Frame2.counter

yay it works fantastic thankyou soo much for everyone helping.
Is there a place on YT or here on this forum where i can learn more on how you guys find out what the problems are? and how to break down to code to understand which bit means what :smile:

Man, try this:

local ButtonStart = script.Parent.Frame.ImageButton

function OnButtonActivated()
    local CurrentValue = script.Parent.Parent.ScreenGui.Frame2.counter.NumberValue.Value -- NumberValue is required
    CurrentValue = CurrentValue + 1
end

ButtonStart.MouseButton1Click:Connect(OnButtonActivated)

ButtonStart is defined as a local, because I’d imagine only this script would use it.
No need to put a local behind the function OnButtonActivated, since this is not inside another function.
CurrentValue = CurrentValue + 1 is how you write your script to add a number
In the last line ButtonStart.MouseButton1Click you have to use MouseButton1Click so the script can register the event properly.

Edit: Is there a number value inside the Gui?

ok i understand i dont need the local bit now i will also have a look at this thankyou all very much i appreciate your help :sunglasses:

1 Like

Many of the YTers aren’t that helpful when it comes to scripting tbh. Try checking out them and see if any help though. You want to understand concepts such as the Roblox explorer hierarchy and all of the properties of objects, as well as how to use the API.

ok i will have a look into this and try learn more about it thankyou all a lot for your help

buttonstart = script.parent.Frame.ImageButton

local function onButtonActivated ()
    local CurrentValue = script.Parent.Parent.ScreenGui2.Frame2.counter.Text
    script.Parent.Parent.ScreenGui2.Frame2.counter.Text = CurrentValue + 1
end

buttonstart.Activated:Connect(onButtonActivated)

Your original code (without the local which will error) “works.” However, the issue was that you were first storing the value of counter.Text in your CurrentValue variable. Then when a player clicked the button, it ends up setting the new text of your counter to be what was already stored plus 1. In other words, you kept setting your text to the old text value plus one, instead of the current value plus one. With your old code, what’d technically work without changing much at all would be doing this instead:

buttonstart = script.parent.Frame.ImageButton

local function onButtonActivated ()
    local CurrentValue = script.Parent.Parent.ScreenGui2.Frame2.counter.Text
    script.Parent.Parent.ScreenGui2.Frame2.counter.Text = script.Parent.Parent.ScreenGui2.Frame2.counter.Text + 1
end

buttonstart.Activated:Connect(onButtonActivated)

Though we know this can be shortened and improved, to be better code, to what we have now:

local ButtonStart = script.Parent.Frame.ImageButton

function OnButtonActivated()
    local CurrentValue = script.Parent.Parent.ScreenGui.Frame2.counter.NumberValue.Value -- NumberValue is required
    CurrentValue = CurrentValue + 1
end

ButtonStart.MouseButton1Click:Connect(OnButtonActivated)

So mainly, beware of setting a variable to the .Text or .Value of something, because it will end up storing the same old value even when you change it at some point later; just know what you’re doing when you do this. Hopefully this helps, and feel free to DM me on here any time to ask questions; have a good weekend!

ok i will look at this too thanks for looking into it

1 Like

This wouldn’t work because once you get the value and store that, it is no longer linked to the property. That would only increase the variable number, not the actual value.

Oh what? It should work because I did not store the value, but referenced the property; I explained it in post I created.