Advertisement
Guest User

thing

a guest
Mar 29th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. --var
  2. local tool = script.Parent
  3. local player = game:GetService("Players").LocalPlayer
  4. local mouse = player:GetMouse()
  5. local sound = tool:WaitForChild("GunFire")
  6. local torso = ""
  7. local reloading = false
  8. local contextActionService = game:GetService("ContextActionService")
  9. local bodytype = nil
  10. local diffrence = 0
  11. local replicatedstorage = game:GetService("ReplicatedStorage")
  12. local gungui = tool:WaitForChild("GunGUI")
  13. local bullets = tool:WaitForChild("Bullets")
  14. --remote events
  15. local equipAnimation = replicatedstorage:WaitForChild("EquipAnimation")
  16. local headshot = replicatedstorage:WaitForChild("Headshot")
  17. local reload = replicatedstorage:WaitForChild("Reload")
  18. local shootevent = replicatedstorage:WaitForChild("ShootEvent")
  19. local unequipanimation = replicatedstorage:WaitForChild("UnequipAnimation")
  20. -- remote function
  21. local checkBodyType = replicatedstorage:WaitForChild("CheckBodyType")
  22. local fetchBulletsLeft = replicatedstorage:WaitForChild("FetchBulletsLeft")
  23. --var
  24.  
  25.  
  26.  
  27.  
  28.  
  29. --------------------------------------------------------
  30. function findBodyType()
  31. bodytype = checkBodyType:InvokeServer(tool)
  32. print(bodytype)
  33. end
  34. function reload()
  35. reloading = true
  36. reload:FireServer(tool.reload)
  37. mouse.Icon = "https://www.roblox.com/library/936489170/reloading"
  38. player.PlayerGui:WaitForChild("GunGUI").Bullets.Text = "Reloading!"
  39. end
  40.  
  41. tool.Equipped:Connect(function(mouse)
  42. gungui:Clone().Parent = player.PlayerGui
  43. findBodyType()
  44. equipAnimation:FireServer(tool.shoot)
  45. mouse.Button1Down:Connect(function()
  46. if bullets.Value <=0 or reloading == true then
  47.  
  48. else
  49. local head = game.Workspace[player.Name].Head.CFrame.lookVector
  50. local mouse = CFrame.new(game.Workspace[player.Name].Head.Position,mouse.hit.p).lookVector
  51. diffrence = (head-mouse)
  52. local ray = Ray.new(tool.Handle.CFrame.p,(player:GetMouse().Hit.p - tool.Handle.CFrame.p).unit*300)
  53. local part,position = game.Workspace:FindPartOnRay(ray.player.Character,false,true)
  54. sound:Play()
  55. if diffrence.magnitude < 1.33 then
  56. shootevent:FireServer(tool,position,part)
  57. bullets.Value = bullets.Value - 1
  58. end
  59. end
  60. end)
  61. local reloadMobileButton = contextActionService:BindAction("ReloadBtn",reload,true,"r")
  62. contextActionService:SetPosition("ReloadBtn",UDim2.new(0.72,-25,.20,-25))
  63. contextActionService:SetImage("ReloadBtn","https://www.roblox.com/library/10952420/Letter-R")
  64. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement