Hey! Recently I made a new Roblox game and one of the main issues we ran into was lag which caused players getting kicked out the server. What are some main things that can cause lag on Roblox and what are some solutions to fix them?
Example:

This is a simple auto clicker. Every 0.5 seconds it sends a event to the server so I can add currency to the players leaderstats, I read that sending a lot of events can cause lag. Is there a solution for something like this?
RunService.RenderStepped:Connect(function()
if not AutoFrame.AutoEnabled.Value then return end
Click() -- Runs the main function that sends the RemoteEvent
end)
Yeah that’s a great way to cause lag. You’ve inserted an event into a RenderStepped meaning it’s firing multiple times a second (at least 40).
i.e Don’t use RenderStepped for operations like this.
Would a better way be something like this?
while wait(5) do
if not AutoFrame.AutoEnabled.Value then return end -- checks if auto click is enabled
Click() -- Runs the main function that sends the RemoteEvent
end
Could you post the Click() function? I’m not sure what the best thing to do would be with the information currently available.
RunService.HeartBeat might be a better solution, but again, it depends.
Yeah sure here is the cooldown and click function
local ClickCooldown, Invoked = 0.5, {}
local function CanClick()
if tick() - (Invoked[Player.Name] or 0) >= (ClickCooldown - 0.1) then
Invoked[Player.Name] = tick()
return true
end
return false
end
local function Click()
if CanClick() then
ClickFrame:TweenSize(UDim2.new(0.3, 0,0.9, 0), "Out", "Sine", 0.08, true);
wait(0.1);
ClickFrame:TweenSize(UDim2.new(0.45, 0,0.9, 0), "In", "Sine", 0.08, true);
EventModule.ClientCall("Click")
end
end
I think that the best way of doing this is to define the RunService.Heartbeat function beforehand and then call it when the player presses the Auto:On button. You could then stop the function when they press the Auto:Off button. This would make it less expensive since it would only run when the Auto:On button has been pressed. In terms of what could be inside the function, you could try this:
-- call the function when they press the button
RunFunction = RunService.HeartBeat:Connect(function()
Click()
end)
-- disconnect the function when they press the button again
RunFunction:Disconnect()
If that’s still too expensive then try doing the time checks in the heartbeat function itself.
I would also do Tween.Completed:Wait() in the Click() function.
Hmm, I see your point. Ill use Heartbeat and see how it goes! Thanks 