Guest User

Untitled

a guest
Jan 10th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.39 KB | None | 0 0
  1. local tool = script.Parent
  2. local camera = game:GetService("Workspace").CurrentCamera
  3. local runService = game:GetService("RunService")
  4. local plr = game:GetService("Players").LocalPlayer
  5. local char = plr.Character or plr.CharacterAdded:Wait()
  6. local toolActivated = false
  7. local mouse = plr:GetMouse()
  8. local UserInputService = game:GetService("UserInputService")
  9. local TweenService = game:GetService("TweenService")
  10. local TweenTime = 0.1
  11. local lookTween
  12. local canPlayTween = false
  13.  
  14.  
  15. tool.Activated:Connect(function()
  16.     toolActivated = true
  17.     canPlayTween = true
  18. end)
  19.  
  20.  
  21. tool.Deactivated:Connect(function()
  22.     toolActivated = false
  23. end)
  24.  
  25. runService.Heartbeat:Connect(function()
  26.     if toolActivated then
  27.         local HumanoidRootPart = char:WaitForChild("HumanoidRootPart")
  28.         local HRPpos = HumanoidRootPart.Position
  29.        
  30.         local goal = {}
  31.         goal.CFrame = CFrame.new(HRPpos, Vector3.new(mouse.Hit.Position.x, HRPpos.y, mouse.Hit.Position.z))
  32.         local tweenInfo = TweenInfo.new(TweenTime)
  33.        
  34.         lookTween = TweenService:Create(HumanoidRootPart, tweenInfo, goal)
  35.         if canPlayTween then
  36.             lookTween:Play()
  37.             canPlayTween = false
  38.         else
  39.             HumanoidRootPart.CFrame = CFrame.new(HRPpos, Vector3.new(mouse.Hit.Position.x, HRPpos.y, mouse.Hit.Position.z))
  40.             lookTween:Cancel()
  41.         end
  42.     end
  43. end)
Advertisement
Add Comment
Please, Sign In to add comment