Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make my pet look in the direction I'm facing?

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!

1 comment

0

hey dude, sorry but I just saw your comment now. I see you’ve accepted my answer so do you still need help or not? I’ll be glad to edit my solution.

2 answers

✓ Accepted answer

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.

1 comment

0

Hey, I couldn't figure it out from what you said, would you be able to give me an example of some sort or even just fixing my script?

i would recommend using something like, pet.Orientation = char.HumanoidRootPart.Orientation you know

1 comment

0

I tried what you said and it works but it's very stuttery/laggy

This discussion is preserved as it was. New answers, comments, and votes are closed.