daily pastebin goal
62%
SHARE
TWEET

Untitled

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