Why is this lag spiking?

https://gyazo.com/d50556873fe3620a38225d55079736ff

As soon as the parent is removed via debris removal, or if I do :Remove()

It lags for a second. Every time. Any idea why? [Edit: only the first time this runs, for any others it’s fine]

local part = script.Parent
local activated = false

function boom()
	local effects = game:GetService("ReplicatedStorage").Effects:WaitForChild("ClownClaymoreEffects"):FindFirstChild("MIDDLE"):Clone()
	effects.Parent = script.Parent.Parent.Claymore
	local explosionSound = script.Parent.Parent.Claymore.explosion:Play()
	task.delay(1, function()
		script.Parent.Parent.Claymore:FindFirstChild("MIDDLE").EXPLOSION01.Enabled = false
		script.Parent.Parent.Claymore:FindFirstChild("MIDDLE").EXPLOSION02.Enabled = false
		script.Parent.Parent.Claymore:FindFirstChild("MIDDLE").EXPLOSION03.Enabled = false
		script.Parent.Parent.Claymore:FindFirstChild("MIDDLE").EXPLOSION04.Enabled = false
		task.wait(4)
		game:GetService("Debris"):AddItem(script.Parent.Parent)
	end)
end



-- Main detection
part.Touched:Connect(function(hit)
	if activated then return end

	local character = hit.Parent
	if not character then return end
	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if not humanoid then return end


		activated = true
		boom()
		

end)

Studio bug…
/////////////////////////

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.