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)
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)
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