I want to make a pet that stays on the side of a player’s head. I have tried but I can’t get it to work. Here is the current script. It is very glitchy. Please help.
local p = script.Parent
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local root = char.Head
while true do
local dir = CFrame.new(p.Position,root.Position+Vector3.new(4,0,0)).LookVector
p.CFrame = p.CFrame + (dir*0.2)
wait()
end
end)
end)
Mainly because a while loop wouldn’t be enough, and won’t keep up with the player, you may wanna use the Heartbeat event (considering that this seem to be done from a server script).
Unrelated, Im not sure how you have that model set or placed. So based on speculation, that would only work with one client. The next time a client joins, that pet will move back and forth from each player since the pet is being told to go to multiple cframes.
Actually, not a bad idea. Just get the vector position in world coordinates of where you want the pet to be (beside the head) and set the position in the body position to that vector pos.
You can find a solution to your problem here . Just use the script Flubberlusch gave and modify the values of BodyForce and BodyVelocity for your pet. I recommend to parent your pet to the player’s HumanoidRootPart and calculate its position with CFrame (Like Flubberlutsch did.).