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
can u send the script that you are using?
Well there are loads of different scripts so anyone of them could be causing it
can u send a video of the issue?
maybe itâs the item collector script thats causing it? send the code here
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
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
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
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
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
Then use your mouse and click to navigate to the area of the spike (or anywhere)
Then set the mode to âDetailedâ mode
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
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