basically this is the only script I can find that works but it doesn't rotate the pet to the direction I'm facing.
Here is my code:
local char = script.Parent.Parent local hum = char:FindFirstChild("Humanoid") local Head = char:FindFirstChild("Head") local pet = script.Parent local maxFloat = 1 local floatInc = 0.025 local sw = false local fl = 0 while true do wait() if not sw then fl = fl + floatInc if fl >= maxFloat then sw = true end else fl = fl - floatInc if fl <=-maxFloat then sw = false end end if pet ~= nil and hum ~= nil and Head ~= nil then if hum.Health >= 0 then local cf = Head.CFrame * CFrame.new(3,2+fl,3) pet.BodyPosition.Position = Vector3.new(cf.x,cf.y,cf.z) pet.BodyGyro.CFrame = Head.CFrame * CFrame.new(3,0,-3) else break end end end
The whole pet with the script inside is under StarterCharacterScripts.
If anyone can help me or even find a better script with working rotation it would be greatly appreciated.
Thanks!
expanding on @MacGames007’s answer, I see you’ve stated that it was laggy. that’s because you are using while wait() do
. please NEVER do that. it goes almost half as fast as you could actually go. if you are doing something really fast then find out how to use RunService
. in this case, I would use RunService.Heartbeat.
nonetheless, I personally suggest that you use AlignOrientation
. you won’t even have to use loops. just add attachment0 to the player and attachment1 to the pet. as the name suggests, pet aligns itself to the player’s orientation automatically, plus you can change the rotation speed and more. if you want to rotate instantly then turn RigidityEnabled
on.
i would recommend using something like, pet.Orientation = char.HumanoidRootPart.Orientation you know