Adding parts to workspace causes lag

i’m trying to make a debris effect and it is causing lag pls help

local total = math.random(2, 3)
for i = 1, total do
 	local part = part()
 	part.Parent = workspace
 	part.Position = ray.Position
 	local attachment0 = Instance.new("Attachment", part)
 	local linearV = Instance.new("LinearVelocity", attachment0)
 	local force = math.random(6, 10)
 	linearV.Attachment0 = attachment0
 	linearV.MaxForce = math.huge
 	linearV.VectorVelocity = dustPart.CFrame.UpVector * force
 	wait(0.15)
 	linearV:Destroy()
 	attachment0:Destroy()
end

how large is the total variable

wait mb glossed over that, could you show a video?

1 Like

do this on the client and instead of using :destroy use Debris:AddItem so you won’t wait 0.15 seconds each part. also it looks like you’re using rays, try to cap the ray unit size to somewhere around 6 or so

1 Like

doing this on the client actually works, thanks a lot!!

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