Hello everyone,
When script.Parent:Destroy() is run, it freezes the server and client for about half a second and then works normally. I have identified that when the script itself is destroyed, that is what causes the lag.
More strangely though, when I destroy the same script for a second time, no lag occurs. Here’s the 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)
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)
Problem is very unlikely to be you server script maybe its local script can you share part of it where Client recives signal from Server like Remote.OnClientEvent ?