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 a click counter?

I new to scripting and was trying to find a way to track how many times I clicked on a button as a practice but after a while of not being able to get it to work I decided to come here, I was wondering if anyone knew what was wrong with my code.

repeat

Clicks = 0

workspace.Button.ClickDetector.MouseClick:Connect(function()
	
	if Clicks<20
	then
		Clicks = Clicks+1
	end
	
	end)
	wait(10)
	Clicks = game.Players.CheezyPatato.PlayerGui.ScreenGui.TextLabel.Text
until Clicks == 20

1 answer

✓ Accepted answer

Insert a screen GUI in to starter GUI. Then insert a frame into the screen GUI. Place it wherever you want. Then insert a text button in the frame. Go on to the properties of the text button and make sure text scaled is on. Put the text to 0. Then insert a number value in the frame. Name the number value "ClickCounter". Now for scripting.

Put a local script in to the text button. Call it whatever you want. In the local script, do this:

script.Parent.MouseButton1Down:Connect(function() local ClickCounter = script.Parent.Parent:WaitForChild("ClickCounter") ClickCounter.Value = ClickCounter.Value + 1 script.Parent.Text = ClickCounter.Value.."Clicks" end)

Now for explaining.

MouseButton1 is left click MouseButton2 is right click MouseButton3 is the scroll wheel.

MouseButton1Down just detects if someone clicks. Then we just set the text to be whatever the amount of clicks a person has had with the word "Clicks", at the end.

If you want, you could even add a click sound.

script.Parent.MouseButton1Down:Connect(function() local ClickCounter = script.Parent.Parent:WaitForChild("ClickCounter") ClickCounter.Value = ClickCounter.Value + 1 script.Parent.Text = ClickCounter.Value.." Clicks"

local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://876939830"
Sound.Parent = workspace
Sound.PlaybackSpeed = 0.8
Sound.Volume = 10
Sound.MaxDistance = 300
Sound:Play()

end)

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