Are bodypositions laggy?

i have a script that sets the part “Bee” to be cloned into workspace and has a bodyposition that is set to the humanoidrootpart as seen in this gyazo

https://gyazo.com/430a792a62a081904f175f16ccb3f4f9

its quite laggy for the first few seconds?

is that just how it is?

while wait() do
BodyPosition.Position = character:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,0,-4)
BodyGyro.CFrame = character:WaitForChild("HumanoidRootPart").CFrame
1 Like

It is because you’re using the “while wait()” loop. Try using this instead!

wait(10)--Wait for you to load in game    
while true do
    BodyPosition.Position = character:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,0,-4)
    BodyGyro.CFrame = character:WaitForChild("HumanoidRootPart").CFrame
end

From my understanding in this script below:

while wait() do
BodyPosition.Position = character:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,0,-4)
BodyGyro.CFrame = character:WaitForChild("HumanoidRootPart").CFrame

The wait will loop the code inside of it after every wait. So I believe this is what’s causing what appears to be “lag”, but is only the script waiting however long it’s supposed to wait before changing its position again. Hope this helps!

You’re much better off using Align Position and Align Rotation.

AP will apply force such that the positions of the attachments align.

AR will apply rotational force to align the rotations.

1 Like

You could use RunService.HeartBeat and it would be kinda similar but not that laggy:

local RunService = game:GetService("RunService")
RunService.HeartBeat:Connect(function())
   BodyPosition.Position = character:WaitForChild("HumanoidRootPart").Position + Vector3.new(0,0,-4)
   BodyGyro.CFrame = character:WaitForChild("HumanoidRootPart").CFrame
end)
1 Like

The lag in the first few seconds is just Studio loading you into the game. There’s not much you can do about that and it’s not your scripts causing it.

This is generally better practice, but won’t solve the lagginess when you first join the place.