Advertisement
Guest User

Lua Script Tool

a guest
Jul 17th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.96 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. local Tool = script.Parent
  5. local Drone = require(script:WaitForChild("Drone"))
  6.  
  7. local Remotes = Tool:WaitForChild("Remotes")
  8. local ServerControl = Remotes:WaitForChild("ServerControl")
  9. local ClientControl = Remotes:WaitForChild("ClientControl")
  10.  
  11. local Player = Players.LocalPlayer
  12. local Character = nil
  13. local Humanoid = nil
  14. local CurrentDrone = nil
  15. local RenderSteppedConn = nil
  16.  
  17. local ToolEquipped = false
  18.  
  19. function CheckIfAlive()
  20.     return (((Character and Character.Parent and Humanoid and Humanoid.Parent and Humanoid.Health > 0 and Player and Player.Parent) and true) or false)
  21. end
  22.  
  23. function CreateDrone(model)
  24.     CurrentDrone = Drone.new(model)
  25.    
  26.     RenderSteppedConn = RunService.RenderStepped:Connect(function(delta)
  27.         if not CurrentDrone then return end
  28.         CurrentDrone:Update(delta)
  29.     end)
  30. end
  31.  
  32. function Equipped()
  33.     ToolEquipped = true
  34.     Character = Player.Character
  35.     Humanoid = Character:FindFirstChildOfClass("Humanoid")
  36. end
  37.  
  38. function Unequipped()
  39.     ToolEquipped = false
  40.     Character = nil
  41.     Humanoid = nil
  42.     if CurrentDrone then
  43.         CurrentDrone:Destroy()
  44.     end
  45.     if RenderSteppedConn then
  46.         RenderSteppedConn:Disconnect()
  47.     end
  48.    
  49.     RenderSteppedConn = nil
  50.     CurrentDrone = nil
  51. end
  52.  
  53. function OnClientInvoke(mode, value)
  54.     if not ToolEquipped or not CheckIfAlive() or not mode then
  55.         return
  56.     end
  57.  
  58.     if mode == "SpawnDrone" then
  59.         CreateDrone(value)
  60.     end
  61. end
  62.  
  63.  
  64. script.Parent.Equipped:Connect(function()
  65.     Player.Character.Humanoid.WalkSpeed = 0
  66. end)
  67.  
  68. script.Parent.Unequipped:Connect(function()
  69.     Player.Character.Humanoid.WalkSpeed = 16
  70. end)
  71.  
  72. Character = Player.Character
  73. Humanoid = Character:FindFirstChildOfClass("Humanoid")
  74.  
  75. Humanoid.Died:Connect(function()
  76.     workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
  77. end)
  78.  
  79.  
  80. ClientControl.OnClientInvoke = OnClientInvoke
  81. Tool.Equipped:Connect(Equipped)
  82. Tool.Unequipped:Connect(Unequipped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement