I have come across a very weird bug that I don’t know how to fix, so I was making some tools for my game, and when I went to test them, the timer was running very slow even though it has a wait of 1 second. Here’s a quick module script I made:
local GameModule = {}
local rep = game:GetService("ReplicatedStorage")
local status = rep:WaitForChild("TimerTime")
function GameModule.Countdown(number)
for i = number, 0, -1 do
status.Value = i;
warn("Counting down...")
wait(1)
end
end
return GameModule
It prints(“Counting down”) after like 3-4 seconds. I don’t know how and why this happened. Thanks for any help that solves this problem.
I assume coroutines could definitely cause that, but I don’t know if it’s that significant to cause such amount of lags. As @Irideon already pointed out, there is no issue that can be found in your code, and the most liked reasoning is lags. Can you screenshot how much PlaceMemory your game has?
Also, in the Developer Console, go to ‘Memory’ and inspect it, see what takes a lot of MB, and if possible, try to use this element less.
I see that there is a lot of usage of memory when it comes to replicating stuff.
How often do remote events fire in your game?
I need the answer alike: Every _ seconds
It’s not good for performance, that is a really possible problem as I do not find any issue in your code.
I suggest optimizing your game, and try to use less Remote Events, as they require the player’s network in order to complete the communication.
If you’d like some tips, here there are (when Remote Events are not necessary):
Change walkspeed/jumppower on the client.
Change the position of a character on the client (as it is automatically replicated).
Play animations on the client (as it is automatically replicated).
There are more things. When you make something, test it on the client and see if it replicates, if it doesn’t and it is a necessary thing for your game, use a Remote Event.
Good day.