Finding the specific cause of lag using microprofiler

I’ve narrowed down one of the causes of lag in my game to a single script:

However, this script has over 1500 lines of code. What’s the best way to find the source of this lag?

What is your script exactly doing? Is it doing like time changes? animations? furniture placing?

It handles everything on the server, except datastores, so functions for when players join/leave, day/night, morphs, houses, etc

Use debug.profilebegin() and debug.profileend() to figure out which parts of your scripts take the longest to process.

For example this:

function test1()
	for i = 1, 10000 do
		math.sin(i)
	end
end

function test2()
	for i = 1, 5000 do
		math.sin(i)
	end
end

while wait() do
	debug.profilebegin("TEST1")
	test1()
	debug.profileend("TEST1")

	debug.profilebegin("TEST2")
	test2()
	debug.profileend("TEST2")
end 

…will cause the profiler to look like this:

4 Likes

Okay thanks, Ill have a shot at this, but it may take some time