Lag issue with rotation scripts

I have a problem, I don’t know why in my game, on public servers with people, rotation scripts are very slow or laggy. When on private servers and Studio, it looks faster.

I know that the problem is not with the script, as I use the same script in several games of mine in which it works perfectly. I thought it was a virus but I haven’t detected any with plugins.


I’m sorry if this is not the correct category, I don’t know which one it is.

Could you send the script here?

yeah! heres
function rotateMod(mod,center,rotation)
local parts ={}
local function scan(parent)
for _,obj in pairs(parent:GetChildren()) do
if (obj:IsA(“BasePart”)) then
table.insert(parts,obj)
end
scan(obj)
end
end
scan(mod)
for _,part in pairs(parts) do
part.CFrame = (centerrotation(center:inverse()*part.CFrame))
end
end

local mod = script.Parent
local step = 1
for i = 0,360,step do
while true do
rotateMod(mod,mod:GetModelCFrame(),CFrame.Angles(0,math.rad(step),0))
wait()
end
wait()
end

Sometimes this can happen because of the graphics settings, is your graphics at max?

I have tried reducing the graphics but the problem persists, even the players mention it and I still can’t find the problem.

I believe this is a lag issue. Avoid nesting :GetChildren and rather use :GetDescendants.


function rotateMod(mod,center,rotation)
local parts ={}
local function scan(parent)
for _,obj in pairs(parent:GetDescendents()) do
if (obj:IsA(“BasePart”)) then
table.insert(parts,obj)
end
end
end

scan(mod)

for _,part in pairs(parts) do
part.CFrame = (centerrotation(center:inverse()*part.CFrame))
end
end

local mod = script.Parent
local step = 1
for i = 0,360,step do
while true do
rotateMod(mod,mod:GetModelCFrame(),CFrame.Angles(0,math.rad(step),0))
wait()
end
wait()
end

You are using wait instead of task.wait. wait will throttle the script, so it will go slower.