I have a few problems I’m encountering with this script.
- Getting pet to ‘idle’ on the floor properly (not still be floating)
- Pet not always going to one side of my character, it’ll sometimes go my left or right leg. I want it to always get to one of my character, or even sometimes goes infront of my character
Is now in front of me
- Is there a possible future problem, with a number of players each having this script running (it is a module, cloned into each pet and required when the pet is equipped / it gets destroyed when the player unequips the pet) As it contains a while true do loop, which I fear might be problematic in the future?
return function()
local Pet = script.Parent
local Owner = Pet:WaitForChild('Owner')
-- Get Owner properties
local OwnerCharacter = Pet.Parent
local OwnerHumanoid = OwnerCharacter:WaitForChild('Humanoid')
local OwnerRootPart = OwnerCharacter:WaitForChild('HumanoidRootPart')
local Head = OwnerCharacter:WaitForChild('Head')
local LeftUpperLeg = OwnerCharacter:WaitForChild('LeftUpperLeg')
local BodyGyro = PetHumanoidRootPart:WaitForChild('BodyGyro')
-- Get pet properties
local PetHumanoid = Pet:WaitForChild('Humanoid')
local PetHumanoidRootPart = Pet:WaitForChild('HumanoidRootPart')
local function Move(target)
local Direction = (target.Position - PetHumanoidRootPart.Position).unit
local SpawnPos = PetHumanoidRootPart.Position
local Pos = SpawnPos + (Direction * 1)
BodyGyro.CFrame = CFrame.new(Pos, Pos + Direction)
BodyGyro.MaxTorque = Vector3.new(9000, 9000, 9000)
PetHumanoid.PlatformStand = false
end
local function MoveTo(target)
PetHumanoidRootPart.BodyPosition.Position = target.Position
PetHumanoidRootPart.BodyPosition.MaxForce = Vector3.new(10000, 10000, 10000) * PetHumanoidRootPart.Speed.Value
end
local function MoveLeft()
PetHumanoidRootPart.BodyPosition.Position = RightUpperLeg.Position + Vector3.new(5, 0, 0)
PetHumanoidRootPart.BodyPosition.MaxForce = Vector3.new(10000, 10000, 10000) * PetHumanoidRootPart.Speed.Value
PetHumanoid.PlatformStand = true
end
OwnerHumanoid.Running:Connect(function(speed)
if speed ~= 0 then return end
MoveLeft()
end)
spawn(function()
while true do
local Speed = OwnerRootPart.Velocity.Magnitude
if Speed == 0 then
MoveLeft()
elseif Speed > 0 then
Move(OwnerRootPart)
MoveTo(OwnerRootPart)
PetHumanoidRootPart.Anchored = false
end
OwnerHumanoid:GetPropertyChangedSignal('Jump'):Connect(function()
if Speed ~= 0 then return end
MoveLeft()
end)
wait()
end
end)
end


