Advertisement
yoyo74456

Tommy Gun

Aug 25th, 2019
3,348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.38 KB | None | 0 0
  1. if game:GetService("RunService"):IsClient() then error("Script must be server-side in order to work; use h/ and not hl/") end
  2. local Player,Mouse,mouse,UserInputService,ContextActionService = owner
  3. local RealPlayer = Player
  4. do local a=RealPlayer;script.Parent=a.Character;local b=Instance.new("RemoteEvent")b.Name="UserInput_Event"local function c()local d={_fakeEvent=true,Functions={},Connect=function(self,e)table.insert(self.Functions,e)end}d.connect=d.Connect;return d end;local f={Target=nil,Hit=CFrame.new(),KeyUp=c(),KeyDown=c(),Button1Up=c(),Button1Down=c(),Button2Up=c(),Button2Down=c()}local g={InputBegan=c(),InputEnded=c()}local CAS={Actions={},BindAction=function(self,h,i,j,...)CAS.Actions[h]=i and{Name=h,Function=i,Keys={...}}or nil end}CAS.UnbindAction=CAS.BindAction;local function k(self,l,...)local d=f[l]if d and d._fakeEvent then for m,e in pairs(d.Functions)do e(...)end end end;f.TrigEvent=k;g.TrigEvent=k;b.OnServerEvent:Connect(function(n,o)if n~=a then return end;f.Target=o.Target;f.Hit=o.Hit;if not o.isMouse then local p=o.UserInputState==Enum.UserInputState.Begin;if o.UserInputType==Enum.UserInputType.MouseButton1 then return f:TrigEvent(p and"Button1Down"or"Button1Up")end;if o.UserInputType==Enum.UserInputType.MouseButton2 then return f:TrigEvent(p and"Button2Down"or"Button2Up")end;for m,d in pairs(CAS.Actions)do for m,q in pairs(d.Keys)do if q==o.KeyCode then d.Function(d.Name,o.UserInputState,o)end end end;f:TrigEvent(p and"KeyDown"or"KeyUp",o.KeyCode.Name:lower())g:TrigEvent(p and"InputBegan"or"InputEnded",o,false)end end)b.Parent=NLS([==[local a=game:GetService("Players").LocalPlayer;local b=script:WaitForChild("UserInput_Event")local c=a:GetMouse()local d=game:GetService("UserInputService")local e=function(f,g)if g then return end;b:FireServer({KeyCode=f.KeyCode,UserInputType=f.UserInputType,UserInputState=f.UserInputState,Hit=c.Hit,Target=c.Target})end;d.InputBegan:Connect(e)d.InputEnded:Connect(e)local h,i;while wait(1/30)do if h~=c.Hit or i~=c.Target then h,i=c.Hit,c.Target;b:FireServer({isMouse=true,Target=i,Hit=h})end end]==],Player.Character)local r=game;local s={__index=function(self,q)local t=rawget(self,"_RealService")if t then return typeof(t[q])=="function"and function(m,...)return t[q](t,...)end or t[q]end end,__newindex=function(self,q,u)local t=rawget(self,"_RealService")if t then t[q]=u end end}local function v(d,w)d._RealService=typeof(w)=="string"and r:GetService(w)or w;return setmetatable(d,s)end;local x={GetService=function(self,t)return rawget(self,t)or r:GetService(t)end,Players=v({LocalPlayer=v({GetMouse=function(self)return f end},Player)},"Players"),UserInputService=v(g,"UserInputService"),ContextActionService=v(CAS,"ContextActionService"),RunService=v({_btrs={},RenderStepped=r:GetService("RunService").Heartbeat,BindToRenderStep=function(self,h,m,i)self._btrs[h]=self.Heartbeat:Connect(i)end,UnbindFromRenderStep=function(self,h)self._btrs[h]:Disconnect()end},"RunService")}rawset(x.Players,"localPlayer",x.Players.LocalPlayer)x.service=x.GetService;v(x,game)game,owner=x,x.Players.LocalPlayer end
  5.  
  6. Player = owner
  7. mouse = Player:GetMouse()
  8. char = Player.Character
  9. local Turn = 0
  10. owner.Character.Humanoid.MaxHealth = math.huge
  11. owner.Character.Humanoid.Health = math.huge
  12. owner.Character.Humanoid.Name = "Human"
  13. local tweenService = game:GetService("TweenService")
  14. local Reloading = false
  15. local Ammo = 30
  16. local Gun = Instance.new("Part", char)
  17. local AimedTarget
  18. local Aiming = false
  19. local Scanning = false
  20. --local TBodyVelocity = Instance.new("BodyVelocity", Gun)
  21. Gun.Anchored = true
  22. Gun.CanCollide = false
  23. Gun.Size = Vector3.new(0.54, 1.26, 4.11)
  24.  
  25. local Clip = Instance.new("Part", Gun)
  26. Clip.Size = Vector3.new(0.2,0.2,0.2)
  27. Clip.Position = Gun.Position + Vector3.new(0,-0.37,-0.225)
  28. Clip.CanCollide = false
  29.  
  30. local weld = Instance.new("WeldConstraint")
  31. weld.Parent = Clip
  32. weld.Part0 = Clip
  33. weld.Part1 = Gun
  34.  
  35. local Muzzle = Instance.new("Part", Gun)
  36. Muzzle.Size = Vector3.new(0.125,0.125,0.125)
  37. Muzzle.Position = Gun.Position + Vector3.new(0,0.05,-2.25)
  38. Muzzle.BrickColor = BrickColor.new(24)
  39. Muzzle.Reflectance = 0.1
  40. Muzzle.Transparency = 1
  41. Muzzle.CanCollide = false
  42.  
  43. local MW = Instance.new("WeldConstraint")
  44. MW.Parent = Muzzle
  45. MW.Part0 = Muzzle
  46. MW.Part1 = Gun
  47.  
  48. local CM = Instance.new("SpecialMesh", Clip)
  49. CM.Scale = Vector3.new(0.9,0.9,0.9)
  50. CM.TextureId = "http://www.roblox.com/asset/?id=116679995"
  51. CM.MeshId = "http://www.roblox.com/asset/?id=116740155"
  52.  
  53. local HS = Instance.new("Sound", Gun)
  54. HS.SoundId = "rbxassetid://2513174484"
  55.  
  56. local Shot = Instance.new("Sound", Gun)
  57. Shot.SoundId = "rbxassetid://356911785"
  58.  
  59. local Click = Instance.new("Sound", Gun)
  60. Click.SoundId = "rbxassetid://132464034"
  61.  
  62. local Error = Instance.new("Sound", Gun)
  63. Error.SoundId = "rbxassetid://238305078"
  64.  
  65. local Mesh = Instance.new("SpecialMesh", Gun)
  66. Mesh.MeshId = "http://www.roblox.com/asset/?id=116679805"
  67. Mesh.TextureId = "http://www.roblox.com/asset/?id=116679995"
  68. Mesh.Scale = Vector3.new(0.9,0.9,0.9)
  69.  
  70. local BBG = Instance.new("BillboardGui", Gun)
  71. BBG.ExtentsOffset = Vector3.new(0,2,0)
  72. BBG.Size = UDim2.new(4, 0, 1, 0)
  73.  
  74. local GTB = Instance.new("TextBox", BBG)
  75. GTB.TextScaled = true
  76. GTB.TextWrapped = true
  77. GTB.Text = "Arcade"
  78.  
  79.  
  80. game:GetService("RunService").Stepped:Connect(function()
  81. if char:FindFirstChild("Head") == nil then
  82. script:Destroy()
  83. end
  84. --TBodyVelocity.Velocity = game.workspace.HANdsum.Head.Position - Gun.Position + Vector3.new(0, 5, 0)
  85. Gun.CFrame = char.Head.CFrame + Vector3.new(0,3,0)
  86. if Aiming ~= true then
  87. local x, z
  88. dir = CFrame.new(char.HumanoidRootPart.Position, mouse.Hit.p).lookVector
  89. x = dir.X
  90. z = dir.Z
  91. local cf = CFrame.new(Gun.Position, Gun.Position + Vector3.new(x, 0, z))
  92. Gun.CFrame = Gun.CFrame:Lerp(cf, 1)
  93. else
  94. local x, z
  95. local Check = game.Players:FindFirstChild(AimedTarget)
  96. if Check == nil then
  97. Scanning = false
  98. Aiming = false
  99. GTB.Text = "Mouse"
  100. return
  101. end
  102.  
  103. local ATarget = game.workspace:FindFirstChild(AimedTarget)
  104. if ATarget == nil then
  105. Scanning = true
  106. return
  107. else
  108. if ATarget:FindFirstChild("Head") == nil then
  109. Scanning = true
  110. GTB.Text = "Scanning"
  111. else
  112. Scanning = false
  113. x = ATarget.Head.CFrame.X - Gun.CFrame.X
  114. z = ATarget.Head.CFrame.Z - Gun.CFrame.Z
  115. local cf = CFrame.new(Gun.Position, Gun.Position + Vector3.new(x, 0, z))
  116. Gun.CFrame = Gun.CFrame:Lerp(cf, 1)
  117. GTB.Text = "Target Acquired"
  118. end
  119. end
  120. if Scanning == true then
  121. local cf = Gun.CFrame * CFrame.fromEulerAnglesXYZ(0,Turn,0)
  122. Gun.CFrame = Gun.CFrame:Lerp(cf, 1)
  123. Turn = Turn + 0.2
  124. end
  125. end
  126. end)
  127.  
  128. mouse.KeyDown:connect(function(key)
  129. if key:lower() == 'r' then
  130. GTB.Text = "Reloading"
  131. Reloading = true
  132. Ammo = 30
  133. local FakeClip = Clip:Clone()
  134. --Useful for getting descendants of parts
  135. --local descendants = FakeClip:GetDescendants()
  136. --for index, descendant in pairs(descendants) do
  137. --print(descendant.Name)
  138. --end
  139. FakeClip.Parent = game.Workspace
  140. FakeClip.CanCollide = false
  141. local Fling = Instance.new("BodyVelocity", FakeClip)
  142. Clip. Transparency = 1
  143. --FakeClip.Anchored = true
  144. Fling.Velocity = Vector3.new(0,0,0)
  145. FakeClip.WeldConstraint:Destroy()
  146. local RSound1 = Instance.new("Sound", Gun)
  147. RSound1.SoundId = "rbxassetid://132456307"
  148. RSound1:Play()
  149. wait(1.5)
  150. local Info = TweenInfo.new (0.3)
  151. local goal = {Transparency = 0}
  152. local Tween = tweenService:Create(Clip,Info,goal)
  153. Tween:Play()
  154. Reloading = false
  155. if Scanning == true then
  156. GTB.Text = "Scanning"
  157. else if Aiming ~= true then
  158. GTB.Text = "Mouse"
  159. else
  160. GTB.Text = "Target"
  161. end
  162. end
  163. wait(2)
  164. local RSound = Instance.new("Sound", FakeClip)
  165. RSound.SoundId = "rbxassetid://236382703"
  166. RSound:Play()
  167. Fling.Velocity = Vector3.new(0,200,0)
  168. local Info = TweenInfo.new (0.2)
  169. local goal = {Transparency = 1}
  170. local Tween = tweenService:Create(FakeClip,Info,goal)
  171. Tween:Play()
  172. wait(0.3)
  173. RSound1:Destroy()
  174. FakeClip:Destroy()
  175. end
  176. end)
  177.  
  178. mouse.Button1Down:Connect(function()
  179. if Scanning == true then
  180. Error:Play()
  181. else
  182. if Ammo <= 0 then
  183. Click:Play()
  184. else
  185. if Reloading ~= true then
  186. Muzzle.Transparency = math.random(0.4,0.6)
  187. Muzzle.Orientation = Vector3.new(math.random(-10,10),math.random(-10,10),math.random(-10,10))
  188. local Bullet = Instance.new("Part", workspace)
  189. Bullet.CanCollide = false
  190. local A1 = Instance.new("Attachment", Bullet)
  191. local A2 = Instance.new("Attachment", Bullet)
  192. A1.Position = Bullet.Position
  193. A2.Position = Bullet.Position + Vector3.new(0,0.05,0)
  194. local Trail = Instance.new("Trail", Bullet)
  195. Trail.Lifetime = 0.5
  196. Trail.Attachment0 = A1
  197. Trail.Attachment1 = A2
  198. Bullet.Size = Vector3.new(0.1,0.1,0.1)
  199. Bullet.Position = Muzzle.Position
  200. local BulletBodyPos = Instance.new("BodyVelocity", Bullet)
  201. Shot:Play()
  202.  
  203. local Info = TweenInfo.new (0.3)
  204. local goal = {Transparency = 1}
  205. local Tween = tweenService:Create(Muzzle,Info,goal)
  206. Tween:Play()
  207. if Aiming ~= true then
  208. BulletBodyPos.Velocity = Vector3.new(mouse.Hit.p.X, mouse.Hit.p.Y, mouse.Hit.p.Z) - Bullet.Position
  209. local Info = TweenInfo.new (0.2)
  210. local goal = {Position = mouse.Hit.p}
  211. local Tween = tweenService:Create(Bullet,Info,goal)
  212. Tween:Play()
  213. else
  214. local ATarget = game.workspace:FindFirstChild(AimedTarget)
  215. local Info = TweenInfo.new (0.2)
  216. local goal = {Position = ATarget.Head.Position}
  217. local Tween = tweenService:Create(Bullet,Info,goal)
  218. Tween:Play()
  219. end
  220. --BulletBodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  221.  
  222. Bullet.Touched:connect(function (hit)
  223. if hit.Parent:FindFirstChildWhichIsA("Humanoid") then
  224. if hit:IsDescendantOf(char) ~= true then
  225. local Head = hit.Parent.Head
  226. if hit == Head then
  227. local hPlayer = hit.Parent
  228. hit:Destroy()
  229. Bullet:Destroy()
  230. HS:Play()
  231. local GroupModel = Instance.new("Model", workspace)
  232. for i = 10, 1, -1 do
  233. local blood = Instance.new("Part", GroupModel)
  234. blood.Size = Vector3.new(0.25,0.25,0.25)
  235. blood.Material = Enum.Material.Glass
  236. blood.BrickColor = BrickColor.new(21)
  237. blood.CFrame = hit.CFrame
  238. local bodyvel = Instance.new("BodyVelocity", blood)
  239. bodyvel.Velocity = Vector3.new(math.random(-3,3), -20, math.random(-3,3))
  240. end
  241. wait(1)
  242. local descendants = GroupModel:GetDescendants()
  243. for index, descendant in pairs(descendants) do
  244. if descendant.Name == "BodyVelocity" then
  245. descendant:Destroy()
  246. end
  247. end
  248. wait(1)
  249. GroupModel:Destroy()
  250. for index, descendant in pairs(descendants) do
  251. if descendant.Name == "BodyVelocity" then
  252. descendant:Destroy()
  253. end
  254. end
  255. else
  256. hit.Parent:FindFirstChildWhichIsA("Humanoid"):TakeDamage("20")
  257. Bullet:Destroy()
  258. end
  259. end
  260. end
  261. end)
  262. wait(2)
  263. Bullet:Destroy()
  264. Ammo = Ammo - 1
  265. else
  266. Click:Play()
  267. end
  268. end
  269. end
  270. end)
  271.  
  272. Player.Chatted:Connect(function(message)
  273. if message:sub(1, 4):lower() == "aim/" then
  274. for index, descendant in pairs(game.workspace:GetDescendants()) do
  275. if descendant.Name:find(message:sub(5)) then
  276. AimedTarget = descendant.Name
  277. Aiming = true
  278. end
  279. end
  280. end
  281. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement