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

how do i make 3 buttons increase a value?

Asked by 4 years ago

notes: - 3 buttons, all have a purpose of increasing the counter by 1 with every press - if i press button1 the counter increases, but if i press button2 or 3 it goes back down to zero or it stays at 1

all the buttons have the same script

aaa = script.Parent.Parent.BrickCounter
Clicks = 0

script.Parent.Parent.BrickCounter.SurfaceGui.TextLabel.Text = Clicks
function onClicked()
    Clicks = Clicks+1
    aaa.SurfaceGui.TextLabel.Text = Clicks
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

thanks in advance

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Add a NumberValue named Clicks within the BrickCounter and change the script to:

local aaa = script.Parent.Parent.BrickCounter
Clicks = aaa.Clicks

script.Parent.Parent.BrickCounter.SurfaceGui.TextLabel.Text = Clicks.Value
function onClicked()
    Clicks.Value = Clicks.Value + 1
    aaa.SurfaceGui.TextLabel.Text = Clicks.Value
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

0
the counter doesn't display anything at all now greendayshade 5 — 4y
0
Can you please show me the output error (if there's any)? masterjosue1998 116 — 4y
1
nvm i just forgot to name the value LMAO thanks for the answer my dude greendayshade 5 — 4y
Ad

Answer this question