Guest User

lul

a guest
Jan 22nd, 2020
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local serverStorage = game:GetService(“ServerStorage”)
  2. local replicatedStorage = game:GetService(“ReplicatedStorage”)
  3. local KOValue = “Kills”
  4. local WOValue = “Wipeouts”
  5. local damage = 30
  6. replicatedStorage.ShootEvent.OnServerEvent:Connect(function(player,tool,position,part)
  7. if game.Workspace[player.Name].Humanoid.Health <= 0 then
  8. — The player is dead, do not do anything
  9. else
  10. local distance = (tool.Handle.CFrame.p – position).magnitude
  11. if game.Workspace:FindFirstChild(player.Name..“‘s Trajectory”) then
  12. game.Workspace:FindFirstChild(player.Name..“‘s Trajectory”):Destroy()
  13. end
  14. local trajectory = Instance.new(“Part”,game.Workspace)
  15. local smoke = serverStorage.SmokeParticle:Clone()
  16. smoke.Parent = tool.Handle
  17. trajectory.BrickColor = BrickColor.new(“Institutional white”)
  18. trajectory.Material = “SmoothPlastic”
  19. trajectory.Name = player.Name..“‘s Trajectory”
  20. trajectory.Transparency = 0.5
  21. trajectory.Anchored = true
  22. trajectory.Locked = true
  23. trajectory.CanCollide = false
  24. trajectory.Size = Vector3.new(0.3,0.3,distance)
  25. for i = 0,distance,6 do
  26. trajectory.CFrame = CFrame.new(tool.Handle.CFrame.p,position) * CFrame.new(0,0,-distance / 2)
  27. wait(0.0001)
  28. end
  29. smoke:Destroy()
  30. if part then
  31. if part.Name == “Head” or part:IsA(“Hat”) and part.Parent:FindFirstChild(“Humanoid”).Health > 0 then
  32. — Boom headshot
  33. replicatedStorage.Headshot:FireClient(player)
  34. damage = 50
  35. end
  36. local humanoid = part.Parent:FindFirstChild(“Humanoid”)
  37. if not humanoid then
  38. humanoid = part.Parent.Parent:FindFirstChild(“Humanoid”)
  39. else
  40. humanoid:TakeDamage(damage)
  41. if humanoid.Health <= 0 then
  42. player.leaderstats[KOValue].Value = player.leaderstats[KOValue].Value + 1
  43. game.Players[humanoid.Parent.Name].leaderstats[WOValue].Value = game.Players[humanoid.Parent.Name].leaderstats[WOValue].Value + 1
  44. end
  45. end
  46. wait(0.25)
  47. if trajectory then
  48. trajectory:Destroy()
  49. end
  50. end
  51. end
  52. end)
  53.  
  54. replicatedStorage.EquipAnimation.OnServerEvent:Connect(function(player,animation)
  55. local newAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
  56. newAnim:Play()
  57. replicatedStorage.UnequipAnimation.OnServerEvent:Connect(function(player,animation)
  58. newAnim:Stop()
  59. for i,v in pairs(game.Workspace:GetChildren()) do
  60. if v.Name == player.Name..“‘s Trajectory” then
  61. v:Destroy()
  62. end
  63. end
  64. end)
  65. replicatedStorage.Reload.OnServerEvent:Connect(function(player,animation)
  66. newAnim:Stop()
  67. local reloadAnim = game.Workspace[player.Name].Humanoid:LoadAnimation(animation)
  68. reloadAnim:Play()
  69. end)
  70. end)
  71.  
  72. function checkBodyType(player,tool)
  73. if game.Workspace[player.Name]:FindFirstChild(“LowerTorso”) then — R15
  74. tool.shoot.AnimationId = “rbxassetid://936531673”
  75. tool.reload.AnimationId = “rbxassetid://937806099”
  76. return “R15”
  77. end
  78. if game.Workspace[player.Name]:FindFirstChild(“Torso”) then — R6
  79. tool.shoot.AnimationId = “rbxassetid://1000874313”
  80. tool.reload.AnimationId = “rbxassetid://937933712”
  81. return “R6”
  82. end
  83. end
  84. replicatedStorage.CheckBodyType.OnServerInvoke = checkBodyType
  85.  
  86. — Local Script, which goes inside the tool
  87.  
  88. local tool = script.Parent — Getting the tool
  89. local player = game:GetService(“Players”).LocalPlayer — Getting the player
  90. local mouse = player:GetMouse() — Getting the mouse
  91. local sound = tool:WaitForChild(“Gunfire”)
  92. local torso = “” — Nothing for now.
  93. local reloading = false — Variable to check if we are currently reloading
  94. local contextActionService = game:GetService(“ContextActionService”) — Allow us to cater for Mobile players
  95. local bodytype = nil — Nil for now but will check whether player is R6 or R15
  96. local difference = 0 — Difference between position of head and mouse
  97. local replicatedstorage = game:GetService(“ReplicatedStorage”)
  98. local gungui = tool:WaitForChild(“GunGUI”)
  99. local bullets = tool:WaitForChild(“Bullets”)
  100. local reloadtime = 3
  101. — Remote Events
  102. local equipAnimation = replicatedstorage:WaitForChild(“EquipAnimation”)
  103. local headshot = replicatedstorage:WaitForChild(“Headshot”)
  104. local reload2 = replicatedstorage:WaitForChild(“Reload”)
  105. local shootevent = replicatedstorage:WaitForChild(“ShootEvent”)
  106. local unequipanimation = replicatedstorage:WaitForChild(“UnequipAnimation”)
  107. — Remote Functions
  108. local checkBodyType = replicatedstorage:WaitForChild(“CheckBodyType”)
  109. local fetchBulletsLeft = replicatedstorage:WaitForChild(“FetchBulletsLeft”)
  110. — Find Body Type
  111. function findBodyType() — Used to determine whether a player is R6 or R15
  112. bodytype = checkBodyType:InvokeServer(tool) — Invoking the Remotefunction to do a check on the server
  113. print(bodytype)
  114. end
  115. — Reloading function
  116. function reload()
  117. reloading = true
  118. reload2:FireServer(tool.reload)
  119. mouse.Icon = “http://www.roblox.com/asset?id=936489163”
  120. player.PlayerGui:WaitForChild(“GunGUI”).Bullets.Text = “Reloading!
  121. wait(reloadtime)
  122. bullets.Value = 6
  123. player.PlayerGui:WaitForChild(“GunGUI”).Bullets.Text = “Bullets: “..bullets.Value
  124. mouse.Icon = “http://www.roblox.com/asset?id=936803874”
  125. equipAnimation:FireServer(tool.shoot)
  126. reloading = false
  127. end
  128. — When the tool is equipped, the following event will run
  129. tool.Equipped:Connect(function(mouse)
  130. gungui:Clone().Parent = player.PlayerGui — We are cloning the Gun GUI into the player’s PlayerGUI
  131. findBodyType() — Calling the function above to check the body type.
  132. equipAnimation:FireServer(tool.shoot) — Calling the equip animation remoteevent so that the server can play the animation
  133. mouse.Icon = “http://www.roblox.com/asset?id=936803874”
  134. mouse.Button1Down:Connect(function()
  135. if bullets.Value <=0 or reloading == true then
  136. — Don’t do anything
  137. else
  138. local head = game.Workspace[player.Name].Head.CFrame.lookVector
  139. local mouse = CFrame.new(game.Workspace[player.Name].Head.Position,mouse.Hit.p).lookVector
  140. difference = (head–mouse)
  141. local ray = Ray.new(tool.Handle.CFrame.p,(player:GetMouse().Hit.p – tool.Handle.CFrame.p).unit*300)
  142. local part,position = game.Workspace:FindPartOnRay(ray,player.Character,false,true)
  143. sound:Play()
  144. if difference.magnitude < 1.33 then
  145. shootevent:FireServer(tool,position,part)
  146. bullets.Value = bullets.Value1
  147. end
  148. end
  149. end)
  150. local reloadMobileButton = contextActionService:BindAction(“ReloadBtn”,reload,true,“r”)
  151. contextActionService:SetPosition(“ReloadBtn”,UDim2.new(0.72,25,0.20,25))
  152. contextActionService:SetImage(“ReloadBtn”,“http://www.roblox.com/asset/?id=10952419”)
  153. end)
  154. tool.Unequipped:Connect(function()
  155. mouse.Icon = “”
  156. unequipanimation:FireServer(tool.shoot)
  157. player.PlayerGui.GunGUI:Destroy()
  158. contextActionService:UnbindAction(“ReloadBtn”)
  159. end)
  160. headshot.OnClientEvent:Connect(function()
  161. player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(0.5,100,0.5,25), “Out”,“Quint”,0.3)
  162. wait(1.5)
  163. player.PlayerGui.GunGUI.Headshot:TweenPosition(UDim2.new(1,0,0.5,25), “In”,“Quint”,0.4)
  164. wait(0.5)
  165. player.PlayerGui.GunGUI.Headshot.Position = UDim2.new(1.5,0,0.5,25)
  166. end)
  167.  
  168.  
  169. game.Players.PlayerAdded:Connect(function(player)
  170. local leaderstats = Instance.new(“IntValue”,player)
  171. leaderstats.Name = “leaderstats”
  172.  
  173. local kills = Instance.new(“IntValue”,leaderstats)
  174. kills.Name = “Kills”
  175. kills.Value = 0
  176.  
  177. local wipeouts = Instance.new(“IntValue”,leaderstats)
  178. wipeouts.Name = “Wipeouts”
  179. wipeouts.Value = 0
  180.  
  181. — Data saving code goes here if you need it
  182. end)
RAW Paste Data