Advertisement
BobMe

MLaser

Dec 21st, 2017
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.96 KB | None | 0 0
  1. local p = game.Players.LocalPlayer
  2. local lol = Instance.new("Tool",p.Backpack)
  3. lol.Name = "LaserGun"
  4. lol.TextureId = "http://www.roblox.com/asset?id=130093050"
  5. local lol2 = Instance.new("Part",lol)
  6. lol2.Name = "Handle"
  7. local lol3 = Instance.new("SpecialMesh",lol2)
  8. lol3.MeshId = "http://www.roblox.com/asset?id=304360628"
  9. lol3.Scale = Vector3.new(0.8, 0.8, 0.8)
  10. lol3.TextureId = "http://www.roblox.com/asset?id=130093033"
  11. local lol4 = Instance.new("PointLight",lol2)
  12. lol4.Color = Color3.new(255, 0, 255)
  13. lol4.Range = 400
  14. lol4.Brightness = 100
  15. local lol5 = Instance.new("Sound",lol2)
  16. lol5.Name = "Fire"
  17. lol5.SoundId = "http://www.roblox.com/asset?id=136523485"
  18. lol5.Pitch = 1.3
  19. lol5.Volume = 5
  20. lol6 = Instance.new("Sound",lol2)
  21. lol6.Name = "Reload"
  22. lol6.SoundId = "http://www.roblox.com/asset?id=166032807"
  23. lol6.Pitch = 1.8
  24. lol6.Volume = 5
  25. local lol7 = Instance.new("Sound",lol2)
  26. lol7.Name = "HitFade"
  27. lol7.Pitch = 0.5
  28. lol7.Volume = 10
  29. lol7.SoundId = "http://www.roblox.com/asset?id=12222242"
  30. -----------------
  31. --| Constants |--
  32. -----------------
  33.  
  34. local SHOT_SPEED = 400
  35. local SHOT_TIME = 5
  36.  
  37. local NOZZLE_OFFSET = Vector3.new(0, 0.4, -1.1)
  38.  
  39. -----------------
  40. --| Variables |--
  41. -----------------
  42.  
  43. local PlayersService = Game:GetService('Players')
  44. local DebrisService = Game:GetService('Debris')
  45.  
  46. local Tool = lol
  47. local Handle = Tool:WaitForChild('Handle')
  48.  
  49. local FireSound = Handle:WaitForChild('Fire')
  50. local ReloadSound = Handle:WaitForChild('Reload')
  51. local HitFadeSound = Handle:WaitForChild('HitFade')
  52.  
  53. local PointLight = Handle:WaitForChild('PointLight')
  54.  
  55. local Character = nil
  56. local Humanoid = nil
  57. local Player = nil
  58.  
  59. local BaseShot = nil
  60.  
  61. -----------------
  62. --| Functions |--
  63. -----------------
  64.  
  65. -- Returns a character ancestor and its Humanoid, or nil
  66. local function FindCharacterAncestor(subject)
  67. if subject and subject ~= Workspace then
  68. local humanoid = subject:FindFirstChild('Humanoid')
  69. if humanoid then
  70. return subject, humanoid
  71. else
  72. return FindCharacterAncestor(subject.Parent)
  73. end
  74. end
  75. return nil
  76. end
  77.  
  78. -- Removes any old creator tags and applies new ones to the specified target
  79. local function ApplyTags(target)
  80. while target:FindFirstChild('creator') do
  81. target.creator:Destroy()
  82. end
  83.  
  84. local creatorTag = Instance.new('ObjectValue')
  85. creatorTag.Value = Player
  86. creatorTag.Name = 'creator' --NOTE: Must be called 'creator' for website stats
  87.  
  88. local iconTag = Instance.new('StringValue')
  89. iconTag.Value = Tool.TextureId
  90. iconTag.Name = 'icon'
  91.  
  92. iconTag.Parent = creatorTag
  93. creatorTag.Parent = target
  94. DebrisService:AddItem(creatorTag, 4)
  95. end
  96.  
  97. -- Returns all objects under instance with Transparency
  98. local function GetTransparentsRecursive(instance, partsTable)
  99. local partsTable = partsTable or {}
  100. for _, child in pairs(instance:GetChildren()) do
  101. if child:IsA('BasePart') or child:IsA('Decal') then
  102. table.insert(partsTable, child)
  103. end
  104. GetTransparentsRecursive(child, partsTable)
  105. end
  106. return partsTable
  107. end
  108.  
  109. local function SelectionBoxify(instance)
  110. local selectionBox = Instance.new('SelectionBox')
  111. selectionBox.Adornee = instance
  112. selectionBox.Color = BrickColor.new('Hot pink')
  113. selectionBox.Parent = instance
  114. return selectionBox
  115. end
  116.  
  117. local function Light(instance)
  118. local light = PointLight:Clone()
  119. light.Range = light.Range + 2
  120. light.Parent = instance
  121. end
  122.  
  123. local function FadeOutObjects(objectsWithTransparency, fadeIncrement)
  124. repeat
  125. local lastObject = nil
  126. for _, object in pairs(objectsWithTransparency) do
  127. object.Transparency = object.Transparency + fadeIncrement
  128. lastObject = object
  129. end
  130. wait()
  131. until lastObject.Transparency >= 1 or not lastObject
  132. end
  133.  
  134. local function Dematerialize(character, humanoid, firstPart)
  135. humanoid.WalkSpeed = 0
  136.  
  137. local parts = {}
  138. for _, child in pairs(character:GetChildren()) do
  139. if child:IsA('BasePart') then
  140. child.Anchored = true
  141. table.insert(parts, child)
  142. elseif child:IsA('LocalScript') or child:IsA('Script') then
  143. child:Destroy()
  144. end
  145. end
  146.  
  147. local selectionBoxes = {}
  148.  
  149. local firstSelectionBox = SelectionBoxify(firstPart)
  150. Light(firstPart)
  151. wait(0.05)
  152.  
  153. for _, part in pairs(parts) do
  154. if part ~= firstPart then
  155. table.insert(selectionBoxes, SelectionBoxify(part))
  156. Light(part)
  157. end
  158. end
  159.  
  160. local objectsWithTransparency = GetTransparentsRecursive(character)
  161. FadeOutObjects(objectsWithTransparency, 0.1)
  162.  
  163. wait(0.5)
  164.  
  165. humanoid.Health = 0
  166. DebrisService:AddItem(character, 2)
  167.  
  168. local fadeIncrement = 0.05
  169. Delay(0.2, function()
  170. FadeOutObjects({firstSelectionBox}, fadeIncrement)
  171. if character then
  172. character:Destroy()
  173. end
  174. end)
  175. FadeOutObjects(selectionBoxes, fadeIncrement)
  176. end
  177.  
  178. local function OnTouched(shot, otherPart)
  179. local character, humanoid = FindCharacterAncestor(otherPart)
  180. if character and humanoid and character ~= Character then
  181. ApplyTags(humanoid)
  182. if shot then
  183. local hitFadeSound = shot:FindFirstChild(HitFadeSound.Name)
  184. if hitFadeSound then
  185. hitFadeSound.Parent = humanoid.Torso
  186. hitFadeSound:Play()
  187. wait()
  188. hitFadeSound:Play()
  189. wait()
  190. hitFadeSound:Play()
  191. wait()
  192. hitFadeSound:Play()
  193. wait()
  194. hitFadeSound:Play()
  195. wait()
  196. hitFadeSound:Play()
  197. wait()
  198. hitFadeSound:Play()
  199. wait()
  200. hitFadeSound:Play()
  201. end
  202. shot:Destroy()
  203. end
  204. Dematerialize(character, humanoid, otherPart)
  205. end
  206. end
  207.  
  208. local function OnEquipped()
  209. Character = Tool.Parent
  210. Humanoid = Character:WaitForChild('Humanoid')
  211. Player = PlayersService:GetPlayerFromCharacter(Character)
  212. end
  213.  
  214. local function OnActivated()
  215. if Tool.Enabled and Humanoid.Health > 0 then
  216. Tool.Enabled = false
  217.  
  218. FireSound:Play()
  219.  
  220. local handleCFrame = Handle.CFrame
  221. local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET)
  222. local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint)
  223.  
  224. local laserShotClone = BaseShot:Clone()
  225. laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2))
  226. local bodyVelocity = Instance.new('BodyVelocity')
  227. bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED
  228. bodyVelocity.Parent = laserShotClone
  229. laserShotClone.Touched:connect(function(otherPart)
  230. OnTouched(laserShotClone, otherPart)
  231. end)
  232. DebrisService:AddItem(laserShotClone, SHOT_TIME)
  233. laserShotClone.Parent = Tool
  234.  
  235. wait(0.001) -- FireSound length
  236.  
  237. ReloadSound:Play()
  238. wait(0.001) -- ReloadSound length
  239.  
  240. Tool.Enabled = true
  241. end
  242. end
  243.  
  244. local function OnUnequipped()
  245.  
  246. end
  247.  
  248. --------------------
  249. --| Script Logic |--
  250. --------------------
  251.  
  252. BaseShot = Instance.new('Part')
  253. BaseShot.Name = 'Effect'
  254. BaseShot.FormFactor = Enum.FormFactor.Custom
  255. BaseShot.Size = Vector3.new(0.2, 0.2, 3)
  256. BaseShot.CanCollide = false
  257. BaseShot.BrickColor = BrickColor.new('Hot pink')
  258. SelectionBoxify(BaseShot)
  259. Light(BaseShot)
  260. HitFadeSound:Clone().Parent = BaseShot
  261.  
  262. Tool.Equipped:connect(OnEquipped)
  263. Tool.Unequipped:connect(OnUnequipped)
  264. Tool.Activated:connect(OnActivated)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement