I have a script that updates at least 100 parts at once, to go from their current state to unanchored, visible, and collidable. If I do this script on the client, there is no lag, but on the server, the clients see a sudden lag spike once the parts are updated. I would like to minimize this lag, and I don’t know why it works fine on the client. It can’t be a performance issue (because running the script on the client uses the same computer as running it on the server in a local server environment), unless Roblox has some other stuff going on behind the scenes.
Here is said script:
for _, child in pairs(parent:GetChildren()) do
if child:IsA("BasePart") then
child.Anchored = false
child.Transparency = parent.Transparency
child.Parent = game.Workspace
local weld = child:FindFirstChildWhichIsA("WeldConstraint")
if weld then weld:Destroy() end
child.CanCollide = true
local randomPosition = Vector3.new(
math.random(-0.3, 0.3),
math.random(-0.3, 0.3),
math.random(-0.3, 0.3)
)
local randomRotation = Vector3.new(
math.random(-7, 7),
math.random(-7, 7),
math.random(-7, 7)
)
child.Position = child.Position + randomPosition
child.CFrame = child.CFrame * CFrame.Angles(
math.rad(randomRotation.X),
math.rad(randomRotation.Y),
math.rad(randomRotation.Z)
)
local t = math.random(40, 70) / 10
Debris(child, t, t - 1)
local direction = (child.Position - hit.Position).Unit
child:ApplyImpulse(direction * 15)
coroutine.wrap(function()
wait(2)
while true do
if child.Velocity.magnitude < 0.001 then
child.Anchored = true
child.CanCollide = false
break
end
wait(0.2)
end
end)()
end
end
parent:Destroy()
(there’s some stuff behind the scenes that handles mouse hit target for clicking a part)