Advertisement
Aeyao

railgun

Jan 10th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. wait(.8)
  2.  
  3. local ign = Instance.new("Folder",workspace)
  4.  
  5. local cf =CFrame.new
  6. local v3 = Vector3.new
  7. local ang = CFrame.Angles
  8. local rad = math.pi/180
  9.  
  10. local p = game.Players.LocalPlayer
  11. local m = p:GetMouse()
  12. local c = p.Character
  13.  
  14. if p.UserId ~= 47951519 then
  15. repeat wait() until false
  16. end
  17.  
  18. local rs = game:GetService("RunService").RenderStepped
  19.  
  20. local cam = workspace.CurrentCamera
  21.  
  22. local gun = Instance.new("Part")
  23. --gun.Size = Vector3.new(0.24, 0.42, 0.13)
  24.  
  25. gun.Size = Vector3.new(4.31, 1.27, 0.85)
  26.  
  27. --[[local gm = Instance.new("SpecialMesh")
  28.  
  29. gm.MeshId = "http://www.roblox.com/asset/?id=11758033"
  30. gm.Offset = Vector3.new(-1.3, 0.2, 0)
  31. gm.Scale = Vector3.new(0.35, 0.4, 0.5)
  32. gm.Parent = gun]]
  33.  
  34. gun.CanCollide = false
  35. gun.Parent = c
  36.  
  37. m.TargetFilter = ign
  38.  
  39. local sound = Instance.new("Sound",gun)
  40. sound.SoundId = "rbxassetid://834546352"
  41. sound.Volume = .4
  42.  
  43. function weld(a,b,co)
  44. local weld = Instance.new("Weld")
  45. weld.Part0 = a
  46. weld.Part1 = b
  47. weld.C0 = co
  48.  
  49. weld.Parent = a
  50. return weld
  51. end
  52.  
  53. local gunweld = weld(gun,c["Right Arm"],cf(.5,-.65,-.5)*ang(90*rad,-0*rad,-90*rad))
  54.  
  55. weld(c["Left Arm"],gun,cf(0.2,-1,-.3)*ang(-40*rad,-20*rad,120*rad))
  56.  
  57. local rw = weld(c["Torso"],c["Right Arm"],cf())
  58. local ro = cf()
  59. local rco = cf()
  60.  
  61. local s = {
  62. gcf = cf(.5,-.65,-.5)*ang(90*rad,-0*rad,-90*rad),
  63. muzzle = cf(-2,0.2,0),
  64. rc0 = cf(1.5,.5,-0.4)*ang(90*rad,0,0),
  65. recoil = cf(0,.5,0)*ang(10*rad,0,0),
  66. colour = BrickColor.new("Really red"),
  67. ecolour = BrickColor.new("Deep orange"),
  68. }
  69.  
  70. function trail(a,b,dtime,tr)
  71.  
  72. local rot = math.random(0,360)
  73. local rotr = math.random(-1,1)
  74. local sizer = math.random(0,100)/100
  75.  
  76. local part = Instance.new("Part",ign)
  77. part.Locked = true
  78. part.Anchored = true
  79. part.CanCollide = false
  80. part.Material = "Neon"
  81. part.BrickColor = s.colour
  82.  
  83. local size = math.random(90,110)/100
  84.  
  85. local dist = (a-b).magnitude
  86. part.Size = v3(size,size,0)
  87.  
  88. local rtco = cf(a,b)*ang(0,0,rot*rad)
  89. part.CFrame = rtco
  90.  
  91. delay(0,function()
  92. for i = tr/2,tr do
  93. part.Transparency = (i/tr)
  94. part.Size = part.Size:lerp(v3(size,size,dist) + v3(sizer,sizer,0)*2,.3)
  95. part.CFrame = rtco
  96. rtco = rtco:lerp(cf(a,b)*cf(0,0,-dist/2)*ang(0,0,rot*rad),.6)
  97. rot = rot + rotr
  98. rs:wait()
  99. end
  100. end)
  101.  
  102. game.Debris:AddItem(part,dtime)
  103. end
  104.  
  105. function explosion(a,siz,dtime,tr,nosound)
  106.  
  107. delay(0,function()
  108. for i = 1,2 do
  109. local rot = math.random(0,360)
  110. local part = Instance.new("Part",ign)
  111. part.Locked = true
  112. part.Anchored = true
  113. part.CanCollide = false
  114. part.CFrame = cf(a)*ang(0,0,rot*rad)
  115. part.Size = Vector3.new()
  116. part.Transparency = .5
  117.  
  118. game.Debris:AddItem(part,3)
  119.  
  120. delay(0,function()
  121. for i = tr/2,tr*4 do
  122. part.Size = part.Size:lerp(Vector3.new(siz,siz,siz)*1.8,.1)
  123. part.Transparency = part.Transparency + .03
  124. part.CFrame = cf(a)*ang(rot*rad*2,rot*rad*-2,rot*rad)
  125. rs:wait()
  126. end
  127. end)
  128.  
  129. end
  130. end)
  131.  
  132. for i = 1,5 do
  133. local rot = math.random(0,360)
  134. local rotr = math.random(-1,1)
  135. local sizer = math.random(0,30)/100
  136.  
  137. local part = Instance.new("Part",ign)
  138. part.Locked = true
  139. part.Anchored = true
  140. part.CanCollide = false
  141. part.Material = "Neon"
  142. part.BrickColor = s.ecolour
  143. part.CFrame = cf(a)*ang(0,0,rot*rad)
  144. part.Size = Vector3.new()
  145.  
  146. if i == 1 and nosound == nil then
  147. local sound = Instance.new("Sound",part)
  148. sound.SoundId = "rbxassetid://597291504"
  149. sound.Volume = 2
  150. sound.Playing = true
  151. game.Debris:AddItem(sound,8)
  152. end
  153.  
  154. delay(0,function()
  155. for i = tr/2,tr do
  156. part.Transparency = (i/tr)
  157. part.Size = part.Size:lerp(v3(siz,siz,0),.5)
  158. part.CFrame = cf(a)*ang(rot*rad*2,rot*rad*-2,rot*rad)
  159. rot = rot + rotr
  160. rs:wait()
  161. end
  162. end)
  163.  
  164. game.Debris:AddItem(part,dtime)
  165. end
  166. end
  167.  
  168. function crater(ray)
  169.  
  170. local hit,pos,rot = workspace:FindPartOnRayWithIgnoreList(ray,{c,ign})
  171.  
  172. local function makepart(rotat)
  173.  
  174. local part = Instance.new("Part",ign)
  175. part.Locked = true
  176. part.Anchored = true
  177. part.CanCollide = true
  178. part.Material = "Slate"
  179. part.BrickColor = hit.BrickColor
  180. part.Size = Vector3.new(5,7,math.random(7,9))
  181.  
  182. part.CFrame = cf(pos,pos+rot) * ang(-90*rad,rotat*rad,0) * cf(0,-3,-5) * ang(math.random(30,50)*rad,0,0)
  183.  
  184. delay(.01,function()
  185. local ocf = part.CFrame
  186. part.Size = part.Size + Vector3.new(0,0,.4)
  187. part.CFrame = ocf
  188. end)
  189.  
  190. game.Debris:AddItem(part,50)
  191.  
  192. end
  193.  
  194. for i = 1,9 do
  195. makepart(i*40)
  196. end
  197.  
  198. end
  199. local hed = false
  200. function shoot()
  201. if hed == true then return end
  202. sound:Play()
  203.  
  204. rco = s.recoil
  205.  
  206. local targ = m.Hit
  207. local ht = m.Target
  208. local muz = gun.CFrame * s.muzzle
  209. local dist = (targ.p-muz.p).magnitude
  210.  
  211. explosion(muz.p,4,1,10,true)
  212.  
  213. trail(muz.p,targ.p,2,20)
  214. trail(muz.p,targ.p,2,20)
  215.  
  216. delay(dist/1500,function()
  217.  
  218. explosion(targ.p,10,2,20)
  219.  
  220. if ht then
  221. if ht.Material == Enum.Material.Grass then
  222. crater(Ray.new((targ*cf(0,0,.5)).p,targ.lookVector*2))
  223. end
  224. end
  225.  
  226. local xp = Instance.new("Explosion",workspace)
  227. xp.Visible = false
  228. xp.Position = targ.p
  229. xp.DestroyJointRadiusPercent = 0
  230. xp.BlastPressure = 100000
  231. xp.BlastRadius = 10
  232.  
  233. xp.Hit:connect(function(h)
  234.  
  235. if h.Parent ~= c and h ~= gun and h.Parent.Parent ~= c then
  236. if h.Parent:FindFirstChildOfClass("Humanoid") then
  237. h.Parent.Humanoid.Health = 0
  238. end
  239. if h.Anchored == false then
  240. h:BreakJoints()
  241. end
  242. end
  243.  
  244. if h.Anchored == false then
  245. local vel = cf(targ.p,h.CFrame.p).lookVector*35
  246.  
  247. h.Velocity = h.Velocity + vel
  248. end
  249.  
  250. end)
  251.  
  252. end)
  253.  
  254. end
  255.  
  256. m.Button1Down:connect(shoot)
  257.  
  258. m.KeyDown:connect(function(k)
  259. if k == "q" then
  260. hed = not hed
  261. end
  262. end)
  263.  
  264. rs:connect(function()
  265. rco = rco:lerp(cf(),.1)
  266. if hed == false then
  267. ro = ang(m.Hit.lookVector.Y,0,0)
  268. else
  269. ro = cf(-0.5,-.5,.5)*ang(math.rad(-40),math.rad(0),math.rad(-20))
  270. end
  271. rw.C0 = s.rc0 * ro * rco
  272.  
  273. local vel = c.HumanoidRootPart.Velocity
  274. local yv = v3(0,(vel.y),0).magnitude
  275. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement