Pets spinning when we don't want them to

A friend and I are working on a pet system. Whenever he spins his avatar, the pets move with him, which is something that we don’t want. Any tips/solutions would be appreciated, thanks!

            while wait() do
                local index = 0
                for n, k in pairs(plr.equipFolder:GetChildren()) do
                    if k.petID.Value == chosen.petID.Value then
                        index = n
                local fullCircle = 2 * math.pi
                local radius = 15

                local function getXAndZPositions(angle)
                    local x = math.cos(angle) * radius
                    local z = math.sin(angle) * radius
                    return x, z

                local angle = index * (fullCircle / #plr.equipFolder:GetChildren())
                local x, z = getXAndZPositions(angle)

                local position = (HRP.CFrame *, 0, z)).p
                local lookAt = HRP.Position
                local goal = {CFrame =, lookAt)}
                local petMove = TweenService:Create(chosen,, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), goal)

first, that task.wait() inside your tweenservice:Create is going to cause issues and slow to the script

then for the spinning, I’d handle it like:
if pet is farther than 2 studs of it’s position, the pet should move to its position
the pet’s position would be its angle and 3 studs away from the player

this pretty much lets the player move 2 studs before the pet needs to move back to its position
and if the player spins within a circle of 2 studs, the pet wouldnt move

the pet’s speed should also be the same or greater than the player’s so if the player walks away, the pet will follow and not get left behind
making the pet faster have things like the pet running ahead, then waiting for the player

First of all, tweenin for such an extremely small amount of time is unnecessary and inefficient. The tween shouldn’t be noticeable anyways. Since you’re already runnin a loop on wats essentially delta time from the last frame.

Secondly, you’re makin the CFrame of the pets to be lookin at the character’s HumanoidRootPart. Remember that CFrames don’t omit orientation so rather ya can set the Position or alternatively use BodyGyro to negate the orientation on a velocity constant.

Change the local variable position from (HRP.CFrame *, 0, z)).p to HRP.Position +, 0, z).

This is pretty much what @SaIamancas said, so you can give them the solution if this works for you.

Wow, @SaIamancas and @goldenstein64 ’ s advice worked. Thank you!

1 Like