Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how do i make 3 buttons increase a value?

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

✓ Accepted answer

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)

3 comments

0

the counter doesn't display anything at all now

0

Can you please show me the output error (if there's any)?

1

nvm i just forgot to name the value LMAO thanks for the answer my dude

This discussion is preserved as it was. New answers, comments, and votes are closed.