So I'm basically making this obby game with different worlds and stuff. For some reason, all of my levels/worlds are always lagging when I play it in roblox player, but not when I run it in the studio. I'm pretty sure this isn't a building problem because they only have around 400 parts.
Also, it's only the moving parts that lag, not player movement or anything.
Here's the script:
(Rotating script for hammer obstacles)
model = script.Parent
model.PrimaryPart = model.PrimaryP
while true do
for i=1, 13, 1 do -- 1+2+...+12+13 = 90 degrees
script.Parent:SetPrimaryPartCFrame(script.Parent:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(i)))
wait()
end
wait(2)
for i=1, 13, 1 do
script.Parent:SetPrimaryPartCFrame(script.Parent:GetPrimaryPartCFrame() * CFrame.Angles(0, 0, math.rad(-i)))
wait()
end
wait(2)
end
I did some research and apparently it's better if you put these in local scripts (currently are regular scripts). I'm not sure if this is the problem, but when I tried to put this in a local script, nothing moved.

4 comments
try and optimize your scripts, and add debounces to events like touched
ok i'll try that. Thanks!
Ok I implimented it. I don't think the problem is that the scripts aren't efficient, because it works in the studio.
I did some research on this before I asked the question, and apparently it might be that this stuff isn't in local scripts? I'm not sure if that is the problem.