Advertisement
IHATEMICROWAVEOVEN

new facing (uses TweenService)

Aug 19th, 2021
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. local TweenService = game:GetService("TweenService")
  2. local turntime = 1 -- Turn time in seconds
  3.  
  4. function Use(...)
  5. local args = {...}
  6. local nearestdistance = math.huge
  7. local nearestplayer
  8. for _, i in pairs(game.Players:GetPlayers()) do
  9. local distancecheck = i:DistanceFromCharacter(args[1].Torso.Position)
  10. if distancecheck < nearestdistance then
  11. nearestplayer = i
  12. nearestdistance = distancecheck
  13. end
  14. end
  15. local cf = {CFrame = CFrame.lookAt(args[1].HumanoidRootPart.Position, nearestplayer.Character.Torso.Position)}
  16. TweenService:Create(args[1].HumanoidRootPart, TweenInfo.new(turntime), cf):Play()
  17. wait(turntime) -- This lets it fully turn before performing its next action
  18. end
  19.  
  20. return Use
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement