I have a script that’s supposed to make your pet follow you, (Credit to TwiistedRoyalty for most part of the script), something like the video in this reply:
This is the script:
local TweenService = game:GetService("TweenService")
local Pet = game.Workspace:WaitForChild("Pet")
local HRP = script.Parent:FindFirstChild("HumanoidRootPart")
local Velocity = Vector3.new(0, 0, 0)
local Speed = 0.2
local Friction = 1
while wait(0.2) do
local TargetVector = HRP.CFrame.Position
local Distance = (TargetVector - Pet.CFrame.Position)
local Force = Distance * Speed
Velocity = (Velocity * (1 - Friction)) + Force
local TweenMove = TweenService:Create(Pet, TweenInfo.new(.2), {CFrame = ((CFrame.new(main.CFrame.Position) * CFrame.Angles(math.clamp(Force.Z, -1, 1), 0, -math.clamp(Force.X, -1, 1))) + Velocity)})
--The line above is the line that i'm having trouble with.
TweenMove:Play()
end
The current issue, is that the pet is not looking where the character is. I thought about converting the CFrame.new(main.CFrame.Position) into main.CFrame, but the Pet started to infinitely rotate while moving, since i have tried any method possible that i know to fix this, and none of them worked, i came here, i really need help with this script, thanks for reading .
There’s alot of math there, and i don’t know how to implement the orientation of the player’s head, or as i said, where the character is looking. But i appreciate your reply
Just change the orientation afterwards in a new line?
It’s also important that you know what it’s doing, from the looks of it it’s just looking where it’s going, so maybe add the orientation change after the pet has stopped for x time.
Well, it isn’t working as expected, but at least it works in a good way! Thanks, if someone wants to know how i made it:
local TweenMove = TweenService:Create(Pet, TweenInfo.new(.2), {CFrame = ((CFrame.new(Pet.CFrame.Position) * CFrame.Angles(math.clamp(Force.Z, -1, 1), 0, -math.clamp(Force.X, -1, 1))) + Velocity)})
local TweenMoveEnd = TweenService:Create(Pet, TweenInfo.new(1), {CFrame = HRP.CFrame})
if Force.Magnitude < 0.5 then
TweenMoveEnd:Play()
else
TweenMove:Play()
end
It checks if Force is less than 0.5, because the script might be thinking, “Oh, the Pet is stopping, ok then, i’m going to play TweenMoveEnd!” TweenMoveEnd would set Pet’s CFrame to HRP’s CFrame. I hope this helps to anyone who needs it!