Advertisement
HowToRoblox

PetClient

Jan 4th, 2022
1,928
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.94 KB | None | 0 0
  1. repeat wait() until script.Parent:FindFirstChild("Pet")
  2.  
  3. local hrp = script.Parent.HumanoidRootPart
  4.  
  5. local moveAnim = script.Parent.Pet.Humanoid:LoadAnimation(script.Parent.Pet.Walking)
  6.  
  7.  
  8. game:GetService("RunService").Heartbeat:Connect(function()
  9.    
  10.     local ray = Ray.new(script.Parent.Pet.HumanoidRootPart.Position, -script.Parent.Pet.HumanoidRootPart.CFrame.UpVector * 1000)
  11.     local part = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
  12.  
  13.     local groundY = part.Position.Y + (part.Size.Y / 2)
  14.  
  15.     local goalCF = hrp.CFrame + Vector3.new(0, groundY + 0.95 - hrp.Position.Y, 0) - (hrp.CFrame.RightVector + hrp.CFrame.LookVector) * 2
  16.  
  17.     script.Parent.Pet.HumanoidRootPart.BodyPosition.Position = goalCF.Position
  18.     script.Parent.Pet.HumanoidRootPart.BodyGyro.CFrame = goalCF
  19.    
  20.    
  21.     if script.Parent.HumanoidRootPart.Velocity.Magnitude > 10 then
  22.  
  23.         if not moveAnim.IsPlaying then moveAnim:Play() end
  24.  
  25.     else
  26.  
  27.         moveAnim:Stop()
  28.     end
  29. end)
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement