In my game, I’m using a single server script to handle character management for real-time fast paced melee combat. The code looks a bit like this:
--stuff
RunService.RenderStepped:Connect(function()
for i,v in pairs(Players:GetChildren()) do
-- do stuff
end
end)
I’m just wondering if this could cause lag for the server. This is only being used in one script, and works fine when I’m playtesting with 1-3 players in game, but I don’t know if I should be worried a more-filled server would slow down because of this.
RenderStepped does not run on the server, it only can run in localscripts which, of course, are run on the client, not the server. (example below)
This could cause possible lag on the client depending on how intensive the script is, but won’t lag the server unless you’re calling remotes between the server and client.
Though Heartbeat is a bit different from RenderStepped, it will not cause lag normally, but it really depends on what you put in there. Putting a huge amount of stuff could cause some lag, but in most cases, it shouldn’t.
Just to add to the conversation, sometimes the issue is not about the lag produced by lot of tasks that HeartBeat should perform, the issue could be that the tasks in HeartBeat doesnt have enough time to finish before a new HeartBeat happens, causing previous tasks to overlap the new ones. RunService will not wait(), it will run the functions in it no matter if the previous functions are not finished yet.