How to detect which and what part of scripts are causing stutter

Hello everyone,
Whenever someone collects an item in my game, the game freezes for about 1 second and then goes back to normal. Does anyone know if there is a tool to locate where the stutter is happening?

the forum is the tool :relieved:
can u send the script that you are using?

2 Likes

Well there are loads of different scripts so anyone of them could be causing it

1 Like

can u send a video of the issue?

1 Like

maybe it’s the item collector script thats causing it? send the code here

2 Likes

It’s nothing really, the game just freezes like a normal stutter for a second after you pick up an item

So there’s no in built lag detector in roblox studio?

it is, just send the code so we can take a look at it, we cant see an issue if we cant see the code. U should send the item pick up code

1 Like

It lags on both the server and client so ill just send you the server script

local rs = game:GetService("ReplicatedStorage")
local remoteEvents = rs:WaitForChild("RemoteEvents")
local collectItemRemote = remoteEvents:WaitForChild("CollectItem")

local dataScript = require(game:GetService("ServerScriptService"):WaitForChild("DataScript"))

script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(function(plr)
	local plrGui = plr:WaitForChild("PlayerGui")
	local infoGui = plrGui:WaitForChild("InfoGUI")
	local infoLabel = infoGui:WaitForChild("InfoLabel")

	if dataScript.serverData['GameStage'] == 'Scavenge' then
		if #dataScript.plrData[plr]['Items'] < 3 then
			collectItemRemote:FireClient(plr, script.Parent.Name)
			table.insert(dataScript.plrData[plr]['Items'], script.Parent.Name)
			script.Parent:Destroy()
		else
			infoLabel.Text = 'Your inventory is full. Put your items in your cart!'
		end
	elseif dataScript.serverData['GameStage'] == 'Intro' then
		infoLabel.Text = 'You cant pick up items yet!'
		task.delay(1.5, function()
			infoLabel.Text = ''
		end)
	end
end)

Sure I sent it here:

local rs = game:GetService("ReplicatedStorage")
local remoteEvents = rs:WaitForChild("RemoteEvents")
local collectItemRemote = remoteEvents:WaitForChild("CollectItem")

local dataScript = require(game:GetService("ServerScriptService"):WaitForChild("DataScript"))

script.Parent:WaitForChild("ClickDetector").MouseClick:Connect(function(plr)
	local plrGui = plr:WaitForChild("PlayerGui")
	local infoGui = plrGui:WaitForChild("InfoGUI")
	local infoLabel = infoGui:WaitForChild("InfoLabel")

	if dataScript.serverData['GameStage'] == 'Scavenge' then
		if #dataScript.plrData[plr]['Items'] < 3 then
			collectItemRemote:FireClient(plr, script.Parent.Name)
			table.insert(dataScript.plrData[plr]['Items'], script.Parent.Name)
			script.Parent:Destroy()
		else
			infoLabel.Text = 'Your inventory is full. Put your items in your cart!'
		end
	elseif dataScript.serverData['GameStage'] == 'Intro' then
		infoLabel.Text = 'You cant pick up items yet!'
		task.delay(1.5, function()
			infoLabel.Text = ''
		end)
	end
end)

it doesnt look like this should be lagging, are u sure it also lags on client side?
And if u try another script in another game instance does it lag aswell? Maybe its a performance issue

1 Like

Yes it lags in other instances. When I’m on Server Side on a local server it freezes for about a second

Use the MicroProfiler, theres a ton of documentation off a quick google search

1 Like

This happened to me but it’s because my map was extremely huge and detailed so I just cut it up into pieces and loaded it in as the player progressed

1 Like

Where can I find a delay if a script was delaying it? I only just see ‘Sleep’ and I’m in the correct zoom

It says ‘worker’ idk it doesnt show the script

This text will be blurred

An interesting thing is it only lags the first time

Sorry for the late response, here’s a little quick overview on micrprofiler:

It should look like this when it’s open. The graph represents the frametime by its height

If you see a huge spike, or anything suspicious that you want to check out, you have to pause it here
image

Then use your mouse and click to navigate to the area of the spike (or anywhere)
image

Then set the mode to “Detailed” mode
image

You’ll then be able to drag and zoom around into whats going on during frames

This is just a quick tutorial, but you should look into how to use debug.profilebegin and debug.profileend to mark areas in your code thatll show in MicroProfiler; it can be a very useful tool

1 Like

This is what I see at a lag spike and it won’t tell me which script the ‘Worker’ thing is from when i hover over it:

Try zooming in and out and dragging around, you’re right now focused on a small area

1 Like