Advertisement
metilol

Untitled

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