Advertisement
Guest User

Hyperlaser Shotgun Script (ROBLOX)

a guest
Apr 16th, 2018
9,986
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.71 KB | None | 0 0
  1. function sandbox(var,func)
  2. local env = getfenv(func)
  3. local newenv = setmetatable({},{
  4. __index = function(self,k)
  5. if k=="script" then
  6. return var
  7. else
  8. return env[k]
  9. end
  10. end,
  11. })
  12. setfenv(func,newenv)
  13. return func
  14. end
  15. cors = {}
  16. mas = Instance.new("Model",game:GetService("Lighting"))
  17. Tool0 = Instance.new("Tool")
  18. Part1 = Instance.new("Part")
  19. SpecialMesh2 = Instance.new("SpecialMesh")
  20. Sound3 = Instance.new("Sound")
  21. Sound4 = Instance.new("Sound")
  22. PointLight5 = Instance.new("PointLight")
  23. Weld6 = Instance.new("Weld")
  24. Weld7 = Instance.new("Weld")
  25. Weld8 = Instance.new("Weld")
  26. LocalScript9 = Instance.new("LocalScript")
  27. Sound10 = Instance.new("Sound")
  28. LocalScript11 = Instance.new("LocalScript")
  29. Part12 = Instance.new("Part")
  30. SpecialMesh13 = Instance.new("SpecialMesh")
  31. PointLight14 = Instance.new("PointLight")
  32. Script15 = Instance.new("Script")
  33. Script16 = Instance.new("Script")
  34. Tool0.Name = "LaserShotGun"
  35. Tool0.Parent = mas
  36. Tool0.TextureId = "http://www.roblox.com/asset?id=130093050"
  37. Tool0.GripForward = Vector3.new(-0.376944453, -0.000461966498, -0.926235735)
  38. Tool0.GripPos = Vector3.new(0, 0.200000003, 0.25000003)
  39. Tool0.GripRight = Vector3.new(0.926235914, -0.000188003658, -0.376944423)
  40. Tool0.GripUp = Vector3.new(1.45519152e-11, 0.999999881, -0.000498756883)
  41. Tool0.ToolTip = "Hyperlaser shotgun!"
  42. Tool0.CanBeDropped = false
  43. Part1.Name = "Handle"
  44. Part1.Parent = Tool0
  45. Part1.Rotation = Vector3.new(-180, 0, -180)
  46. Part1.CanCollide = false
  47. Part1.FormFactor = Enum.FormFactor.Custom
  48. Part1.Size = Vector3.new(0.580000222, 1.34000099, 4.48000145)
  49. Part1.CFrame = CFrame.new(-13.710001, 102.57, 47.8400002, -0.999997616, 9.05775108e-12, -1.88592058e-08, -9.13322282e-12, 0.999997377, 6.28057464e-08, -1.53668083e-08, -6.28641601e-08, -0.999999821)
  50. Part1.BottomSurface = Enum.SurfaceType.Smooth
  51. Part1.TopSurface = Enum.SurfaceType.Smooth
  52. Part1.Position = Vector3.new(-13.710001, 102.57, 47.8400002)
  53. Part1.Orientation = Vector3.new(0, -180, 0)
  54. SpecialMesh2.Parent = Part1
  55. SpecialMesh2.MeshId = "http://www.roblox.com/asset?id=130099641"
  56. SpecialMesh2.Scale = Vector3.new(1, 0.75, 1.5)
  57. SpecialMesh2.TextureId = "http://www.roblox.com/asset?id=130093033"
  58. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  59. SpecialMesh2.Scale = Vector3.new(1, 0.75, 1.5)
  60. Sound3.Name = "Fire"
  61. Sound3.Parent = Part1
  62. Sound3.Pitch = 0.5
  63. Sound3.SoundId = "http://www.roblox.com/asset?id=130113322"
  64. Sound3.Volume = 1
  65. Sound4.Name = "Reload"
  66. Sound4.Parent = Part1
  67. Sound4.Pitch = 0.5
  68. Sound4.SoundId = "http://www.roblox.com/asset?id=130113370"
  69. PointLight5.Parent = Part1
  70. PointLight5.Color = Color3.new(0, 1, 1)
  71. PointLight5.Range = 6
  72. PointLight5.Color = Color3.new(0, 1, 1)
  73. Weld6.Parent = Part1
  74. Weld6.C0 = CFrame.new(0, 0, 0, -3.17205462e-08, 2.98023188e-08, 0.999999821, 4.42590249e-08, 0.999999821, -2.98023295e-08, -1, 4.42590107e-08, -3.17205746e-08)
  75. Weld6.C1 = CFrame.new(0, 0, 0, -3.17205462e-08, 2.98023188e-08, 0.999999821, 4.42590249e-08, 0.999999821, -2.98023295e-08, -1, 4.42590107e-08, -3.17205746e-08)
  76. Weld6.Part0 = Part1
  77. Weld6.Part1 = Part1
  78. Weld7.Parent = Part1
  79. Weld7.C0 = CFrame.new(0, 0, 0, -0.823671401, 0.00976598449, 0.566983223, 0.566961288, -0.00514982874, 0.823728263, 0.0109643862, 0.999939024, -0.00129515026)
  80. Weld7.C1 = CFrame.new(0, 0, 0, -0.823671401, 0.00976598449, 0.566983223, 0.566961288, -0.00514982874, 0.823728263, 0.0109643862, 0.999939024, -0.00129515026)
  81. Weld7.Part0 = Part1
  82. Weld7.Part1 = Part1
  83. Weld8.Parent = Part1
  84. Weld8.C0 = CFrame.new(0, 0, 0, -0.823671401, 0.00976598449, 0.566983223, 0.566961288, -0.00514982874, 0.823728263, 0.0109643862, 0.999939024, -0.00129515026)
  85. Weld8.C1 = CFrame.new(-0.399999499, 0, 1.1920929e-07, -0.823670983, 0.00976601522, 0.566982925, 0.56696099, -0.00514967833, 0.823727846, 0.0109643312, 0.999939024, -0.00129529205)
  86. Weld8.Part0 = Part1
  87. Weld8.Part1 = Part12
  88. LocalScript9.Name = "ToolScript"
  89. LocalScript9.Parent = Tool0
  90. table.insert(cors,sandbox(LocalScript9,function()
  91. -----------------
  92. --| Constants |--
  93. -----------------
  94.  
  95. local SHOT_SPEED =250
  96. local SHOT_TIME = 1
  97.  
  98. local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
  99.  
  100. -----------------
  101. --| Variables |--
  102. -----------------
  103.  
  104. local PlayersService = Game:GetService('Players')
  105. local DebrisService = Game:GetService('Debris')
  106.  
  107. local Tool = script.Parent
  108. local Handle = Tool:WaitForChild('Handle')
  109.  
  110. local FireSound = Handle:WaitForChild('Fire')
  111. local ReloadSound = Handle:WaitForChild('Reload')
  112. local HitFadeSound = script:WaitForChild('HitFade')
  113.  
  114. local PointLight = Handle:WaitForChild('PointLight')
  115.  
  116. local Character = nil
  117. local Humanoid = nil
  118. local Player = nil
  119.  
  120. local BaseShot = nil
  121.  
  122. -----------------
  123. --| Functions |--
  124. -----------------
  125.  
  126. -- Returns a character ancestor and its Humanoid, or nil
  127. local function FindCharacterAncestor(subject)
  128. if subject and subject ~= Workspace then
  129. local humanoid = subject:FindFirstChild('Humanoid')
  130. if humanoid then
  131. return subject, humanoid
  132. else
  133. return FindCharacterAncestor(subject.Parent)
  134. end
  135. end
  136. return nil
  137. end
  138.  
  139. -- Removes any old creator tags and applies new ones to the specified target
  140. local function ApplyTags(target)
  141. while target:FindFirstChild('creator') do
  142. target.creator:Destroy()
  143. end
  144.  
  145. local creatorTag = Instance.new('ObjectValue')
  146. creatorTag.Value = Player
  147. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  148.  
  149. local iconTag = Instance.new('StringValue')
  150. iconTag.Value = Tool.TextureId
  151. iconTag.Name = 'icon'
  152.  
  153. iconTag.Parent = creatorTag
  154. creatorTag.Parent = target
  155. DebrisService:AddItem(creatorTag, 4)
  156. end
  157.  
  158. -- Returns all objects under instance with Transparency
  159. local function GetTransparentsRecursive(instance, partsTable)
  160. local partsTable = partsTable or {}
  161. for _, child in pairs(instance:GetChildren()) do
  162. if child:IsA('BasePart') or child:IsA('Decal') then
  163. table.insert(partsTable, child)
  164. end
  165. GetTransparentsRecursive(child, partsTable)
  166. end
  167. return partsTable
  168. end
  169.  
  170. local function SelectionBoxify(instance)
  171. local selectionBox = Instance.new('SelectionBox')
  172. selectionBox.Adornee = instance
  173. selectionBox.Color = BrickColor.new('Toothpaste')
  174. selectionBox.Parent = instance
  175. return selectionBox
  176. end
  177.  
  178. local function Light(instance)
  179. local light = PointLight:Clone()
  180. light.Range = light.Range + 2
  181. light.Parent = instance
  182. end
  183.  
  184. local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
  185. repeat
  186. local lastObject = nil
  187. for _, object in pairs(objectsWithTransparency) do
  188. object.Transparency = object.Transparency + fadeIncrement
  189. lastObject = object
  190. end
  191. wait()
  192. until lastObject.Transparency >= 1 or not lastObject
  193. end
  194.  
  195. local function Dematerialize(character, humanoid, firstPart)
  196. humanoid.WalkSpeed = 0
  197.  
  198. local parts = {}
  199. for _, child in pairs(character:GetChildren()) do
  200. if child:IsA('BasePart') then
  201. child.Anchored = true
  202. table.insert(parts, child)
  203. elseif child:IsA('LocalScript') or child:IsA('Script') then
  204. child:Destroy()
  205. end
  206. end
  207.  
  208. local selectionBoxes = {}
  209.  
  210. local firstSelectionBox = SelectionBoxify(firstPart)
  211. Light(firstPart)
  212. wait(0.05)
  213.  
  214. for _, part in pairs(parts) do
  215. if part ~= firstPart then
  216. table.insert(selectionBoxes, SelectionBoxify(part))
  217. Light(part)
  218. end
  219. end
  220.  
  221. local objectsWithTransparency = GetTransparentsRecursive(character)
  222. FadeOutObjects(objectsWithTransparency, 0.1)
  223.  
  224. wait(0.5)
  225.  
  226. humanoid.Health = 0
  227. DebrisService:AddItem(character, 2)
  228.  
  229. local fadeIncrement = 0.05
  230. Delay(0.2, function()
  231. FadeOutObjects({firstSelectionBox}, fadeIncrement)
  232. if character then
  233. character:Destroy()
  234. end
  235. end)
  236. FadeOutObjects(selectionBoxes, fadeIncrement)
  237. end
  238.  
  239. local function OnTouched(shot, otherPart)
  240. local character, humanoid = FindCharacterAncestor(otherPart)
  241. if character and humanoid and character ~= Character then
  242. ApplyTags(humanoid)
  243. if shot then
  244. local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
  245. if hitFadeSound then
  246. hitFadeSound.Parent = humanoid.Torso
  247. hitFadeSound:Play()
  248. end
  249. shot:Destroy()
  250. end
  251. Dematerialize(character, humanoid, otherPart)
  252. end
  253. end
  254.  
  255. local function OnEquipped()
  256. Character = Tool.Parent
  257. Humanoid = Character:WaitForChild('Humanoid')
  258. Player = PlayersService:GetPlayerFromCharacter(Character)
  259. end
  260.  
  261. local function OnActivated()
  262. if Tool.Enabled and Humanoid.Health > 0 then
  263. Tool.Enabled = false
  264.  
  265. FireSound:Play()
  266.  
  267. local handleCFrame = Handle.CFrame
  268. local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
  269. for i=1, 25 do
  270. local target=Humanoid.TargetPoint
  271. target = CFrame.Angles((0.5 - math.random()) * 2 * (math.random()*.04),
  272. (0.5 - math.random()) * 2 * (math.random()*.04),
  273. (0.5 - math.random()) * 2 * (math.random()*.04)) * target
  274.  
  275. local shotCFrame = CFrame.new(firingPoint, target)
  276.  
  277.  
  278. local laserShotClone = BaseShot:Clone()
  279. laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
  280. local bodyVelocity = Instance.new('BodyVelocity')
  281. bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
  282. bodyVelocity.Parent = laserShotClone
  283. laserShotClone.Touched:connect(function(otherPart)
  284. OnTouched(laserShotClone, otherPart)
  285. end)
  286. DebrisService:AddItem(laserShotClone, SHOT_TIME)
  287. laserShotClone.Parent = Tool
  288. end
  289.  
  290. Tool.GripPos=Vector3.new(0,.2,-.5)
  291. Tool.GripRight=Vector3.new(0.926,.2,-0.377)
  292. wait(.1)
  293. Tool.GripPos=Vector3.new(0,.2,-0.25)
  294. Tool.GripRight=Vector3.new(0.926,.15,-0.377)
  295. wait(.1)
  296. Tool.GripPos=Vector3.new(0,0.2,0)
  297. Tool.GripRight=Vector3.new(0.926,.1,-0.377)
  298. wait(.1)
  299. Tool.GripPos=Vector3.new(0,0.2,0.125)
  300. Tool.GripRight=Vector3.new(0.926,.05,-0.377)
  301. wait(.1)
  302. Tool.GripPos=Vector3.new(0,0.2,0.25)
  303. Tool.GripRight=Vector3.new(0.926,0,-0.377)
  304. wait(.25)
  305.  
  306. ReloadSound:Play()
  307. wait(1.25) -- ReloadSound length
  308.  
  309. Tool.Enabled = true
  310. end
  311. end
  312.  
  313. local function OnUnequipped()
  314.  
  315. end
  316.  
  317. --------------------
  318. --| Script Logic |--
  319. --------------------
  320.  
  321. BaseShot = Instance.new('Part')
  322. BaseShot.Name = 'Effect'
  323. BaseShot.FormFactor = Enum.FormFactor.Custom
  324. BaseShot.Size = Vector3.new(0.2, 0.2, 3)
  325. BaseShot.CanCollide = false
  326. BaseShot.BrickColor = BrickColor.new('Toothpaste')
  327. SelectionBoxify(BaseShot)
  328. Light(BaseShot)
  329. HitFadeSound:Clone().Parent = BaseShot
  330.  
  331. Tool.Equipped:connect(OnEquipped)
  332. Tool.Unequipped:connect(OnUnequipped)
  333. Tool.Activated:connect(OnActivated)
  334.  
  335. end))
  336. Sound10.Name = "HitFade"
  337. Sound10.Parent = LocalScript9
  338. Sound10.SoundId = "http://www.roblox.com/asset?id=130113415"
  339. LocalScript11.Name = "MouseIcon"
  340. LocalScript11.Parent = Tool0
  341. table.insert(cors,sandbox(LocalScript11,function()
  342. local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
  343. local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'
  344.  
  345. local Tool = script.Parent
  346.  
  347. local Mouse = nil
  348.  
  349. local function UpdateIcon()
  350. if Mouse then
  351. Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
  352. end
  353. end
  354.  
  355. local function OnEquipped(mouse)
  356. Mouse = mouse
  357. UpdateIcon()
  358. end
  359.  
  360. local function OnChanged(property)
  361. if property == 'Enabled' then
  362. UpdateIcon()
  363. end
  364. end
  365.  
  366. Tool.Equipped:connect(OnEquipped)
  367. Tool.Changed:connect(OnChanged)
  368.  
  369. end))
  370. Part12.Name = "Barrel2"
  371. Part12.Parent = Tool0
  372. Part12.Rotation = Vector3.new(180, 0, 180)
  373. Part12.FormFactor = Enum.FormFactor.Custom
  374. Part12.Size = Vector3.new(0.580000222, 1.34000099, 4.48000145)
  375. Part12.CFrame = CFrame.new(-14.1099997, 102.57, 47.8400002, -0.999998212, -2.97932274e-08, 2.60770321e-08, -2.98114173e-08, 0.999998033, -1.00757461e-07, -4.09781933e-08, -1.94995664e-07, -0.999999881)
  376. Part12.BottomSurface = Enum.SurfaceType.Smooth
  377. Part12.TopSurface = Enum.SurfaceType.Smooth
  378. Part12.Position = Vector3.new(-14.1099997, 102.57, 47.8400002)
  379. Part12.Orientation = Vector3.new(0, 180, 0)
  380. SpecialMesh13.Parent = Part12
  381. SpecialMesh13.MeshId = "http://www.roblox.com/asset?id=130099641"
  382. SpecialMesh13.Scale = Vector3.new(1, 0.75, 1.5)
  383. SpecialMesh13.TextureId = "http://www.roblox.com/asset?id=130093033"
  384. SpecialMesh13.MeshType = Enum.MeshType.FileMesh
  385. SpecialMesh13.Scale = Vector3.new(1, 0.75, 1.5)
  386. PointLight14.Parent = Part12
  387. PointLight14.Color = Color3.new(0, 1, 1)
  388. PointLight14.Range = 6
  389. PointLight14.Color = Color3.new(0, 1, 1)
  390. Script15.Name = "Weld"
  391. Script15.Parent = Tool0
  392. table.insert(cors,sandbox(Script15,function()
  393. function Weld(x,y)
  394. local W = Instance.new("Weld")
  395. W.Part0 = x
  396. W.Part1 = y
  397. local CJ = CFrame.new(x.Position)
  398. local C0 = x.CFrame:inverse()*CJ
  399. local C1 = y.CFrame:inverse()*CJ
  400. W.C0 = C0
  401. W.C1 = C1
  402. W.Parent = x
  403. end
  404.  
  405. function Get(A)
  406. if A.className == "Part" or A.className == "UnionOperation"then
  407. Weld(script.Parent.Handle, A)
  408. A.Anchored = false
  409. else
  410. local C = A:GetChildren()
  411. for i=1, #C do
  412. Get(C[i])
  413. end
  414. end
  415. end
  416.  
  417. function Finale()
  418. Get(script.Parent)
  419. end
  420.  
  421. script.Parent.Equipped:connect(Finale)
  422. script.Parent.Unequipped:connect(Finale)
  423. Finale()
  424. end))
  425. Script16.Name = "WeldArm"
  426. Script16.Parent = Tool0
  427. table.insert(cors,sandbox(Script16,function()
  428. Tool = script.Parent
  429.  
  430. local arms = nil
  431. local torso = nil
  432. local welds = {}
  433. local down = false
  434.  
  435. function Equip(mouse)
  436. wait(0.01)
  437. arms = {Tool.Parent:FindFirstChild("Left Arm"), Tool.Parent:FindFirstChild("Right Arm")}
  438. torso = Tool.Parent:FindFirstChild("Torso")
  439. if arms ~= nil and torso ~= nil then
  440. local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
  441. if sh ~= nil then
  442. local yes = true
  443. if yes then
  444. yes = false
  445. sh[1].Part1 = nil
  446. sh[2].Part1 = nil
  447. local weld1 = Instance.new("Weld")
  448. weld1.Part0 = torso
  449. weld1.Parent = torso
  450. weld1.Part1 = arms[1]
  451. weld1.C1 = CFrame.new(-.1, 1.25, .6) * CFrame.fromEulerAnglesXYZ(math.rad(290), math.rad(10), math.rad(-90))
  452. welds[1] = weld1
  453. local weld2 = Instance.new("Weld")
  454. weld2.Part0 = torso
  455. weld2.Parent = torso
  456. weld2.Part1 = arms[2]
  457. weld2.C1 = CFrame.new(-1, -0.5, 0.35) * CFrame.fromEulerAnglesXYZ(math.rad(-90), math.rad(-30), 0)
  458. welds[2] = weld2
  459. end
  460. else
  461. print("sh")
  462. end
  463. else
  464. print("arms")
  465. end
  466. end
  467.  
  468. function Unequip(mouse)
  469. if arms ~= nil and torso ~= nil then
  470. local sh = {torso:FindFirstChild("Left Shoulder"), torso:FindFirstChild("Right Shoulder")}
  471. if sh ~= nil then
  472. local yes = true
  473. if yes then
  474. yes = false
  475. sh[1].Part1 = arms[1]
  476. sh[2].Part1 = arms[2]
  477. welds[1].Parent = nil
  478. welds[2].Parent = nil
  479. end
  480. else
  481. print("sh")
  482. end
  483. else
  484. print("arms")
  485. end
  486. end
  487.  
  488. Tool.Equipped:connect(Equip)
  489. Tool.Unequipped:connect(Unequip)
  490.  
  491. end))
  492. for i,v in pairs(mas:GetChildren()) do
  493. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  494. pcall(function() v:MakeJoints() end)
  495. end
  496. mas:Destroy()
  497. for i,v in pairs(cors) do
  498. spawn(function()
  499. pcall(v)
  500. end)
  501. end
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement