Er1x_Official

client side projectile raycast system

Dec 10th, 2022
1,552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.91 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local Players = game:GetService("Players")
  3.  
  4. local Player = Players.LocalPlayer
  5. local Mouse = Player:GetMouse()
  6.  
  7. local Tool = script.Parent
  8. local RemoteEvent = Tool:WaitForChild("RemoteEvent")
  9. local GunConfig = Tool:WaitForChild("Configuration")
  10.  
  11. local Activated = false
  12. local Heartbeat
  13.  
  14. function Fire()
  15.     RemoteEvent:FireServer(Mouse.Hit.Position)
  16. end
  17.  
  18. Tool.Activated:Connect(function()
  19.     Activated = true
  20.     if GunConfig:WaitForChild("IsAutomatic").Value == true then
  21.         Heartbeat = RunService.Heartbeat:Connect(function()
  22.             if Activated then
  23.                 Fire()
  24.             else
  25.                 Heartbeat:Disconnect()
  26.             end
  27.         end)
  28.     else
  29.         RemoteEvent:FireServer(Mouse.Hit.Position)
  30.     end
  31. end)
  32.  
  33. Tool.Deactivated:Connect(function()
  34.     task.delay(.01,function()
  35.         if Activated then
  36.             Activated = false
  37.         end
  38.     end)
  39. end)
  40.  
  41. Tool.Unequipped:Connect(function()
  42.     Activated = false
  43. end)
Advertisement
Add Comment
Please, Sign In to add comment