Advertisement
Guest User

Auto Hyperlaser Script ROBLOX

a guest
Apr 16th, 2018
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.01 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. LocalScript6 = Instance.new("LocalScript")
  24. Sound7 = Instance.new("Sound")
  25. LocalScript8 = Instance.new("LocalScript")
  26. Tool0.Name = "Automatic Hyperlaser"
  27. Tool0.Parent = mas
  28. Tool0.TextureId = "http://www.roblox.com/asset?id=130093050"
  29. Tool0.GripPos = Vector3.new(0, -0.100000001, 0.75)
  30. Tool0.ToolTip = "Edited by JoshuaKempfert"
  31. Tool0.CanBeDropped = false
  32. Part1.Name = "Handle"
  33. Part1.Parent = Tool0
  34. Part1.FormFactor = Enum.FormFactor.Custom
  35. Part1.Size = Vector3.new(0.580000222, 1.34000099, 2.48000145)
  36. Part1.BottomSurface = Enum.SurfaceType.Smooth
  37. Part1.TopSurface = Enum.SurfaceType.Smooth
  38. SpecialMesh2.Parent = Part1
  39. SpecialMesh2.MeshId = "http://www.roblox.com/asset?id=130099641"
  40. SpecialMesh2.Scale = Vector3.new(0.649999976, 0.649999976, 0.649999976)
  41. SpecialMesh2.TextureId = "http://www.roblox.com/asset?id=130093033"
  42. SpecialMesh2.MeshType = Enum.MeshType.FileMesh
  43. SpecialMesh2.Scale = Vector3.new(0.649999976, 0.649999976, 0.649999976)
  44. Sound3.Name = "Fire"
  45. Sound3.Parent = Part1
  46. Sound3.SoundId = "http://www.roblox.com/asset?id=130113322"
  47. Sound4.Name = "Reload"
  48. Sound4.Parent = Part1
  49. Sound4.SoundId = "http://www.roblox.com/asset?id=130113370"
  50. PointLight5.Parent = Part1
  51. PointLight5.Color = Color3.new(0, 1, 1)
  52. PointLight5.Range = 6
  53. PointLight5.Color = Color3.new(0, 1, 1)
  54. LocalScript6.Name = "ToolScript"
  55. LocalScript6.Parent = Tool0
  56. table.insert(cors,sandbox(LocalScript6,function()
  57. --Edited by JoshuaKempfert
  58. --No plagiarism intended..
  59.  
  60. -----------------
  61. --| Constants |--
  62. -----------------
  63.  
  64. local SHOT_SPEED = 250
  65. local SHOT_TIME = 0
  66.  
  67. local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
  68.  
  69. -----------------
  70. --| Variables |--
  71. -----------------
  72.  
  73. local PlayersService = Game:GetService('Players')
  74. local DebrisService = Game:GetService('Debris')
  75.  
  76. local Tool = script.Parent
  77. local Handle = Tool:WaitForChild('Handle')
  78.  
  79. local FireSound = Handle:WaitForChild('Fire')
  80. local ReloadSound = Handle:WaitForChild('Reload')
  81. local HitFadeSound = script:WaitForChild('HitFade')
  82.  
  83. local PointLight = Handle:WaitForChild('PointLight')
  84.  
  85. local Character = nil
  86. local Humanoid = nil
  87. local Player = nil
  88.  
  89. local BaseShot = nil
  90. local MouseHeld=false
  91.  
  92. -----------------
  93. --| Functions |--
  94. -----------------
  95.  
  96. -- Returns a character ancestor and its Humanoid, or nil
  97. local function FindCharacterAncestor(subject)
  98. if subject and subject ~= Workspace then
  99. local humanoid = subject:FindFirstChild('Humanoid')
  100. if humanoid then
  101. return subject, humanoid
  102. else
  103. return FindCharacterAncestor(subject.Parent)
  104. end
  105. end
  106. return nil
  107. end
  108.  
  109. -- Removes any old creator tags and applies new ones to the specified target
  110. local function ApplyTags(target)
  111. while target:FindFirstChild('creator') do
  112. target.creator:Destroy()
  113. end
  114.  
  115. local creatorTag = Instance.new('ObjectValue')
  116. creatorTag.Value = Player
  117. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  118.  
  119. local iconTag = Instance.new('StringValue')
  120. iconTag.Value = Tool.TextureId
  121. iconTag.Name = 'icon'
  122.  
  123. iconTag.Parent = creatorTag
  124. creatorTag.Parent = target
  125. DebrisService:AddItem(creatorTag, 4)
  126. end
  127.  
  128. -- Returns all objects under instance with Transparency
  129. local function GetTransparentsRecursive(instance, partsTable)
  130. local partsTable = partsTable or {}
  131. for _, child in pairs(instance:GetChildren()) do
  132. if child:IsA('BasePart') or child:IsA('Decal') then
  133. table.insert(partsTable, child)
  134. end
  135. GetTransparentsRecursive(child, partsTable)
  136. end
  137. return partsTable
  138. end
  139.  
  140. local function SelectionBoxify(instance)
  141. local selectionBox = Instance.new('SelectionBox')
  142. selectionBox.Adornee = instance
  143. selectionBox.Color = BrickColor.new('Toothpaste')
  144. selectionBox.Parent = instance
  145. return selectionBox
  146. end
  147.  
  148. local function Light(instance)
  149. local light = PointLight:Clone()
  150. light.Range = light.Range + 2
  151. light.Parent = instance
  152. end
  153.  
  154. local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
  155. repeat
  156. local lastObject = nil
  157. for _, object in pairs(objectsWithTransparency) do
  158. object.Transparency = object.Transparency + fadeIncrement
  159. lastObject = object
  160. end
  161. wait()
  162. until lastObject.Transparency >= 1 or not lastObject
  163. end
  164.  
  165. local function Dematerialize(character, humanoid, firstPart)
  166. humanoid.WalkSpeed = 0
  167.  
  168. local parts = {}
  169. for _, child in pairs(character:GetChildren()) do
  170. if child:IsA('BasePart') then
  171. child.Anchored = true
  172. table.insert(parts, child)
  173. elseif child:IsA('LocalScript') or child:IsA('Script') then
  174. child:Destroy()
  175. end
  176. end
  177.  
  178. local selectionBoxes = {}
  179.  
  180. local firstSelectionBox = SelectionBoxify(firstPart)
  181. Light(firstPart)
  182. wait(0.05)
  183.  
  184. for _, part in pairs(parts) do
  185. if part ~= firstPart then
  186. table.insert(selectionBoxes, SelectionBoxify(part))
  187. Light(part)
  188. end
  189. end
  190.  
  191. local objectsWithTransparency = GetTransparentsRecursive(character)
  192. FadeOutObjects(objectsWithTransparency, 0.1)
  193.  
  194. wait(0.5)
  195.  
  196. humanoid.Health = 0
  197. DebrisService:AddItem(character, 2)
  198.  
  199. local fadeIncrement = 0.05
  200. Delay(0.2, function()
  201. FadeOutObjects({firstSelectionBox}, fadeIncrement)
  202. if character then
  203. character:Destroy()
  204. end
  205. end)
  206. FadeOutObjects(selectionBoxes, fadeIncrement)
  207. end
  208.  
  209. local function OnTouched(shot, otherPart)
  210. local character, humanoid = FindCharacterAncestor(otherPart)
  211. if character and humanoid and character ~= Character then
  212. ApplyTags(humanoid)
  213. if shot then
  214. local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
  215. if hitFadeSound then
  216. hitFadeSound.Parent = humanoid.Torso
  217. hitFadeSound:Play()
  218. end
  219. shot:Destroy()
  220. end
  221. Dematerialize(character, humanoid, otherPart)
  222. end
  223. end
  224.  
  225. local function OnEquipped()
  226. Character = Tool.Parent
  227. Humanoid = Character:WaitForChild('Humanoid')
  228. Player = PlayersService:GetPlayerFromCharacter(Character)
  229. end
  230.  
  231. local function OnActivated()
  232. MouseHeld=true
  233. coroutine.resume(coroutine.create(function()
  234.  
  235. while (MouseHeld==true and wait(SHOT_TIME)) do
  236. if Humanoid.Health > 0 then
  237. coroutine.resume(coroutine.create(function()
  238. Tool.Enabled = false
  239.  
  240. FireSound:Play()
  241.  
  242. local handleCFrame = Handle.CFrame
  243. local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
  244. local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint)
  245.  
  246. local laserShotClone = BaseShot:Clone()
  247. laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
  248. local bodyVelocity = Instance.new('BodyVelocity')
  249. bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
  250. bodyVelocity.Parent = laserShotClone
  251. laserShotClone.Touched:connect(function(otherPart)
  252. OnTouched(laserShotClone, otherPart)
  253. end)
  254. DebrisService:AddItem(laserShotClone, 5)
  255. laserShotClone.Parent = Tool
  256.  
  257. wait(0.5) -- FireSound length
  258. if MouseHeld==false then
  259. ReloadSound:Play()
  260. wait(0.75) -- ReloadSound length
  261. end
  262.  
  263. Tool.Enabled = true
  264. end))
  265. end
  266. end
  267. end))
  268. end
  269.  
  270. local function OnUnequipped()
  271.  
  272. end
  273.  
  274. local function onDeactivated()
  275. MouseHeld=false
  276. end
  277.  
  278. --------------------
  279. --| Script Logic |--
  280. --------------------
  281.  
  282. BaseShot = Instance.new('Part')
  283. BaseShot.Name = 'Effect'
  284. BaseShot.FormFactor = Enum.FormFactor.Custom
  285. BaseShot.Size = Vector3.new(0.2, 0.2, 3)
  286. BaseShot.CanCollide = false
  287. BaseShot.BrickColor = BrickColor.new('Toothpaste')
  288. SelectionBoxify(BaseShot)
  289. Light(BaseShot)
  290. HitFadeSound:Clone().Parent = BaseShot
  291.  
  292. Tool.Equipped:connect(OnEquipped)
  293. Tool.Unequipped:connect(OnUnequipped)
  294. Tool.Activated:connect(OnActivated)
  295. Tool.Deactivated:connect(onDeactivated)
  296.  
  297. end))
  298. Sound7.Name = "HitFade"
  299. Sound7.Parent = LocalScript6
  300. Sound7.SoundId = "http://www.roblox.com/asset?id=130113415"
  301. LocalScript8.Name = "MouseIcon"
  302. LocalScript8.Parent = Tool0
  303. table.insert(cors,sandbox(LocalScript8,function()
  304. local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
  305. local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'
  306.  
  307. local Tool = script.Parent
  308.  
  309. local Mouse = nil
  310.  
  311. local function UpdateIcon()
  312. if Mouse then
  313. Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
  314. end
  315. end
  316.  
  317. local function OnEquipped(mouse)
  318. Mouse = mouse
  319. UpdateIcon()
  320. end
  321.  
  322. local function OnChanged(property)
  323. if property == 'Enabled' then
  324. UpdateIcon()
  325. end
  326. end
  327.  
  328. Tool.Equipped:connect(OnEquipped)
  329. Tool.Changed:connect(OnChanged)
  330.  
  331. end))
  332. for i,v in pairs(mas:GetChildren()) do
  333. v.Parent = game:GetService("Players").LocalPlayer.Backpack
  334. pcall(function() v:MakeJoints() end)
  335. end
  336. mas:Destroy()
  337. for i,v in pairs(cors) do
  338. spawn(function()
  339. pcall(v)
  340. end)
  341. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement