Hello!
So here I have this code, which is supposed to make the pet :
- Follow me
- Play a walking animation when the player is walking and stop it when the player is idle
The problem :
The only problem is that the pet does play the animation when the player walks, but does not stop. I cannot seem to figure why
The code :
local function Follow(pet)
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local BodyPosition = Instance.new("BodyPosition", pet:WaitForChild("Pet"))
BodyPosition.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
local BodyGyro = Instance.new("BodyGyro", pet:WaitForChild("Pet"))
BodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
Character.Humanoid.Running:Connect(function(speed)
local MovementAnimationTrack = pet:FindFirstChild("AnimationController"):FindFirstChild("Animator"):LoadAnimation(pet:FindFirstChild("Animations"):FindFirstChild("Movement"))
if speed > 0 then
MovementAnimationTrack:Play()
MovementAnimationTrack:AdjustSpeed(2)
end
if speed == 0 then
MovementAnimationTrack:Stop()
end
end)
while wait() do
BodyPosition.Position = HumanoidRootPart.Position + PetPosition
BodyGyro.CFrame = HumanoidRootPart.CFrame
pet:WaitForChild("Pet").Orientation = HumanoidRootPart.Orientation + Vector3.new(0,180,0)
end
end
Any help is appreciated!