Click Counter broken

Hi!
I have a click counter here that if you click it, should give you 1.
Instead, it gives you infinity.
What is wrong?

local plr = game.Players.LocalPlayer
local RS = game:GetService("RunService")
local leaderstats = plr.leaderstats
local parent = script.Parent

parent.MouseButton1Click:Connect(function()
local c
c = RS.RenderStepped:Connect(function()
	wait()
	leaderstats.Clicks.Value = leaderstats.Clicks.Value + 1
end)
end)


2 Likes

Notice: I still dont know why-there’s no loop, really.

I would remove the RenderStepped function because that is a form of loop that runs every frame or so (if I remember correctly). Here is an example of what I would do instead:

local plr = game.Players.LocalPlayer
local RS = game:GetService("RunService")
local leaderstats = plr.leaderstats
local parent = script.Parent

parent.MouseButton1Click:Connect(function()
	wait()
	leaderstats.Clicks.Value = leaderstats.Clicks.Value + 1
end)

Hope this helps!

1 Like

The Render stepped runs every time a user’s screen updates, based on their frame rate. It’s an event which fires like 60 times per second on a device that runs the game at 60 fps. Refer to @DoudGeorges and the Dev hub: RunService | Documentation - Roblox Creator Hub

2 Likes

image
Works now! You left in 1 eztra end), still works thouigh.

1 Like

Happy to help! (I removed the extra end, thanks for letting me know)

1 Like

image
Welp, Still know I tried.

3 Likes