Why does this Cframe script lag so bad?

This door is supposed to open and close with cframe,
In an empty baseplate it’s animated like butter, but in the game its super choppy
The script looks fine to me. Especially since it works in other places just fine, What could cause lag to Cframe?

Example of the lag : https://gyazo.com/fa604b5e9bc473c56a67d21a8949eb21

Example of it not lagging : https://gyazo.com/6faf08149bbbb7b49bfaeda333f29d98

Script Snippet
			for i = 3,(Door.Size.z / 0.15)  do
				Door.CFrame = Door.CFrame + (Door.CFrame.lookVector * 0.15)
				
				wait()
			end
			end)
			
			spawn(function()
			for i = 3,(Door2.Size.z / 0.15) do
				Door2.CFrame = Door2.CFrame + (Door2.CFrame.lookVector * 0.15)
				
				wait()
			end
			end)```

Are you doing this with a local or server script?
I’m not sure, but would lag be explained by if it’s local the client creates the CFrame, it gets sent to the server, then back to the clients instead of just being created on the server and sent to all clients?

If you CFrame it and want it really smooth why not Tween it? You can calculate the start point CFrame and the end point and have it tween (without the loop) over whatever time frame you choose.

This thread looks like it has some helpful information for you:

1 Like

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