Advertisement
Prephy

HyperLaserGun

May 25th, 2021 (edited)
1,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.04 KB | None | 0 0
  1. --Converted into script by Protofer_S, im bored
  2. wait()
  3. local player = owner
  4. local Tool = Instance.new("Tool") Tool.Name='RedHyperLaser' Tool.TextureId='rbxassetid://209727372'  Tool.CanBeDropped=false
  5. local Handle = Instance.new("Part",Tool) Handle.Size=Vector3.new(0.58, 1.34, 2.48) Handle.Name='Handle'
  6. Tool.GripUp=Vector3.new(0,1,0) Tool.GripRight=Vector3.new(1,0,0) Tool.GripPos=Vector3.new(0, -0.1, 0.75) Tool.GripForward=Vector3.new(0,0,-1)
  7. local mesh = Instance.new("SpecialMesh",Handle) mesh.MeshId='http://www.roblox.com/asset/?id=130099641' mesh.TextureId='rbxassetid://209727730'
  8. local light = Instance.new("PointLight",Handle) light.Color=Color3.new(1, 0, 0) light.Brightness=1 light.Range=6
  9. mesh.Scale=Vector3.new(0.65, 0.65, 0.65)
  10. Tool.Parent=player.Backpack
  11.  
  12. local firesound = Instance.new("Sound",Handle) firesound.SoundId='http://www.roblox.com/asset?id=130113322' firesound.PlaybackSpeed=0.85 firesound.Name='Fire'
  13. local reloadsound = Instance.new("Sound",Handle) reloadsound.SoundId='http://www.roblox.com/asset?id=130113370' reloadsound.PlaybackSpeed=0.85 reloadsound.Name='Reload'
  14. local fade = Instance.new("Sound",Handle) fade.SoundId='http://www.roblox.com/asset?id=130113415' fade.PlaybackSpeed=0.85 fade.Name='HitFade'
  15.  
  16. --Rescripted by Luckymaxer
  17.  
  18. function icon()
  19.     NLS([[
  20.     local MOUSE_ICON = 'rbxasset://textures/GunCursor.png'
  21. local RELOADING_ICON = 'rbxasset://textures/GunWaitCursor.png'
  22.  
  23. local Tool = script.Parent
  24.  
  25. local Mouse = nil
  26.  
  27. local function UpdateIcon()
  28.     if Mouse then
  29.         Mouse.Icon = Tool.Enabled and MOUSE_ICON or RELOADING_ICON
  30.     end
  31. end
  32.  
  33. local function OnEquipped(mouse)
  34.     Mouse = mouse
  35.     UpdateIcon()
  36. end
  37.  
  38. local function OnChanged(property)
  39.     if property == 'Enabled' then
  40.         UpdateIcon()
  41.     end
  42. end
  43.  
  44. Tool.Equipped:connect(OnEquipped)
  45. Tool.Changed:connect(OnChanged)
  46.  
  47.    
  48.     ]],Tool)
  49. end
  50.  
  51. function scrip()
  52.     icon()
  53.     NLS([[
  54.     --Rescripted by Luckymaxer
  55.  
  56. Tool = script.Parent
  57. Handle = Tool:WaitForChild("Handle")
  58.  
  59. Players = game:GetService("Players")
  60.  
  61. ServerControl = Tool:WaitForChild("ServerControl")
  62. ClientControl = Tool:WaitForChild("ClientControl")
  63.  
  64. ClientControl.OnClientInvoke = (function(Mode, Value)
  65.     if Mode == "PlaySound" and Value then
  66.         Value:Play()
  67.     end
  68. end)
  69.  
  70. function InvokeServer(Mode, Value, arg)
  71.     pcall(function()
  72.         ServerControl:InvokeServer(Mode, Value, arg)
  73.     end)
  74. end
  75.  
  76. function Equipped(Mouse)
  77.     Character = Tool.Parent
  78.     Player = Players:GetPlayerFromCharacter(Character)
  79.     Humanoid = Character:FindFirstChild("Humanoid")
  80.     if not Player or not Humanoid or Humanoid.Health == 0 then
  81.         return
  82.     end
  83.     Mouse.Button1Down:connect(function()
  84.         InvokeServer("Click", true, Mouse.Hit.p)
  85.     end)
  86. end
  87.  
  88. local function Unequipped()
  89.    
  90. end
  91.  
  92. Tool.Equipped:connect(Equipped)
  93. Tool.Unequipped:connect(Unequipped)
  94.     ]],Tool)
  95. end
  96.  
  97. scrip()
  98.  
  99. Tool.Activated:Connect(function()
  100.     local test1 = Handle:FindFirstChild('Fire')
  101.     if test1 then
  102.     else
  103.         firesound = Instance.new("Sound",Handle) firesound.SoundId='http://www.roblox.com/asset?id=130113322' firesound.PlaybackSpeed=0.85 firesound.Name='Fire'
  104.     end
  105.     local test2 = Handle:FindFirstChild('Reload')
  106.     if test2 then
  107.     else
  108.         reloadsound = Instance.new("Sound",Handle) reloadsound.SoundId='http://www.roblox.com/asset?id=130113370' reloadsound.PlaybackSpeed=0.85 reloadsound.Name='Reload'
  109.     end
  110.     local test3 = Handle:FindFirstChild('HitFade')
  111.     if test3 then
  112.     else
  113.         fade = Instance.new("Sound",Handle) fade.SoundId='http://www.roblox.com/asset?id=130113415' fade.PlaybackSpeed=0.85 fade.Name='HitFade'
  114.     end
  115.     local test4 = Handle:FindFirstChild('PointLight')
  116.     if not test4 then
  117.         light = Instance.new("PointLight",Handle) light.Color=Color3.new(1, 0, 0) light.Brightness=1 light.Range=6
  118.     end
  119. end)
  120.  
  121. Players = game:GetService("Players")
  122. Debris = game:GetService("Debris")
  123.  
  124. Speed = 100
  125. Duration = 2
  126.  
  127. NozzleOffset = Vector3.new(0, 0.4, -1.1)
  128.  
  129. Sounds = {
  130.     Fire =  firesound,
  131.     Reload =  reloadsound,
  132.     HitFade = fade
  133. }
  134.  
  135. PointLight = light
  136.  
  137. ServerControl = (Tool:FindFirstChild("ServerControl") or Instance.new("RemoteFunction"))
  138. ServerControl.Name = "ServerControl"
  139. ServerControl.Parent = Tool
  140.  
  141. ClientControl = (Tool:FindFirstChild("ClientControl") or Instance.new("RemoteFunction"))
  142. ClientControl.Name = "ClientControl"
  143. ClientControl.Parent = Tool
  144.  
  145. ServerControl.OnServerInvoke = (function(player, Mode, Value, arg)
  146.     if player ~= Player or Humanoid.Health == 0 or not Tool.Enabled then
  147.         return
  148.     end
  149.     if Mode == "Click" and Value then
  150.         Activated(arg)
  151.     end
  152. end)
  153.  
  154. function InvokeClient(Mode, Value)
  155.     pcall(function()
  156.         ClientControl:InvokeClient(Player, Mode, Value)
  157.     end)
  158. end
  159.  
  160. function TagHumanoid(humanoid, player)
  161.     local Creator_Tag = Instance.new("ObjectValue")
  162.     Creator_Tag.Name = "creator"
  163.     Creator_Tag.Value = player
  164.     Debris:AddItem(Creator_Tag, 2)
  165.     Creator_Tag.Parent = humanoid
  166. end
  167.  
  168. function UntagHumanoid(humanoid)
  169.     for i, v in pairs(humanoid:GetChildren()) do
  170.         if v:IsA("ObjectValue") and v.Name == "creator" then
  171.             v:Destroy()
  172.         end
  173.     end
  174. end
  175.  
  176. function FindCharacterAncestor(Parent)
  177.     if Parent and Parent ~= game:GetService("Workspace") then
  178.         local humanoid = Parent:FindFirstChildOfClass("Humanoid")
  179.         if humanoid then
  180.             return Parent, humanoid
  181.         else
  182.             return FindCharacterAncestor(Parent.Parent)
  183.         end
  184.     end
  185.     return nil
  186. end
  187.  
  188. function GetTransparentsRecursive(Parent, PartsTable)
  189.     local PartsTable = (PartsTable or {})
  190.     for i, v in pairs(Parent:GetChildren()) do
  191.         local TransparencyExists = false
  192.         pcall(function()
  193.             local Transparency = v["Transparency"]
  194.             if Transparency then
  195.                 TransparencyExists = true
  196.             end
  197.         end)
  198.         if TransparencyExists then
  199.             table.insert(PartsTable, v)
  200.         end
  201.         GetTransparentsRecursive(v, PartsTable)
  202.     end
  203.     return PartsTable
  204. end
  205.  
  206. function SelectionBoxify(Object)
  207.     local SelectionBox = Instance.new("SelectionBox")
  208.     SelectionBox.Adornee = Object
  209.     SelectionBox.Color = BrickColor.new("Really red")
  210.     SelectionBox.Parent = Object
  211.     return SelectionBox
  212. end
  213.  
  214. local function Light(Object)
  215.     local Light = PointLight:Clone()
  216.     Light.Range = (Light.Range + 2)
  217.     Light.Parent = Object
  218. end
  219.  
  220. function FadeOutObjects(Objects, FadeIncrement)
  221.     repeat
  222.         local LastObject = nil
  223.         for i, v in pairs(Objects) do
  224.             v.Transparency = (v.Transparency + FadeIncrement)
  225.             LastObject = v
  226.         end
  227.         wait()
  228.     until LastObject.Transparency >= 1 or not LastObject
  229. end
  230.  
  231. function Dematerialize(character, humanoid, FirstPart)
  232.     if not character or not humanoid then
  233.         return
  234.     end
  235.  
  236.     humanoid.WalkSpeed = 0
  237.  
  238.     local Parts = {}
  239.  
  240.     for i, v in pairs(character:GetChildren()) do
  241.         if v:IsA("BasePart") then
  242.             v.Anchored = true
  243.             table.insert(Parts, v)
  244.         elseif v:IsA("LocalScript") or v:IsA("Script") then
  245.             v:Destroy()
  246.         end
  247.     end
  248.  
  249.     local SelectionBoxes = {}
  250.  
  251.     local FirstSelectionBox = SelectionBoxify(FirstPart)
  252.     Light(FirstPart)
  253.     wait(0.05)
  254.  
  255.     for i, v in pairs(Parts) do
  256.         if v ~= FirstPart then
  257.             table.insert(SelectionBoxes, SelectionBoxify(v))
  258.             Light(v)
  259.         end
  260.     end
  261.  
  262.     local ObjectsWithTransparency = GetTransparentsRecursive(character)
  263.     FadeOutObjects(ObjectsWithTransparency, 0.1)
  264.  
  265.     wait(0.5)
  266.  
  267.     character:BreakJoints()
  268.     humanoid.Health = 0
  269.  
  270.     Debris:AddItem(character, 2)
  271.  
  272.     local FadeIncrement = 0.05
  273.     Delay(0.2, function()
  274.         FadeOutObjects({FirstSelectionBox}, FadeIncrement)
  275.         if character and character.Parent then
  276.             character:Destroy()
  277.         end
  278.     end)
  279.     FadeOutObjects(SelectionBoxes, FadeIncrement)
  280. end
  281.  
  282. function Touched(Projectile, Hit)
  283.     if not Hit or not Hit.Parent then
  284.         return
  285.     end
  286.     local character, humanoid = FindCharacterAncestor(Hit)
  287.     if character and humanoid and character ~= Character then
  288.         local ForceFieldExists = false
  289.         for i, v in pairs(character:GetChildren()) do
  290.             if v:IsA("ForceField") then
  291.                 print('Ew a forcefield, lets kill it :)')
  292.                 --ForceFieldExists = true
  293.             end
  294.         end
  295.         if not ForceFieldExists then
  296.             if Projectile then
  297.                 local HitFadeSound = Projectile:FindFirstChild(Sounds.HitFade.Name)
  298.                 local torso = humanoid.Torso
  299.                 if HitFadeSound and torso then
  300.                     HitFadeSound.Parent = torso
  301.                     HitFadeSound:Play()
  302.                 end
  303.             end
  304.             Dematerialize(character, humanoid, Hit)
  305.         end
  306.         if Projectile and Projectile.Parent then
  307.             Projectile:Destroy()
  308.         end
  309.     end
  310. end
  311.  
  312. function Equipped()
  313.     Character = Tool.Parent
  314.     Player = Players:GetPlayerFromCharacter(Character)
  315.     Humanoid = Character:FindFirstChild("Humanoid")
  316.     if not Player or not Humanoid or Humanoid.Health == 0 then
  317.         return
  318.     end
  319. end
  320.  
  321. function Activated(target)
  322.     if Tool.Enabled and Humanoid.Health > 0 then
  323.         Tool.Enabled = false
  324.  
  325.         InvokeClient("PlaySound", Sounds.Fire)
  326.  
  327.         local HandleCFrame = Handle.CFrame
  328.         local FiringPoint = HandleCFrame.p + HandleCFrame:vectorToWorldSpace(NozzleOffset)
  329.         local ShotCFrame = CFrame.new(FiringPoint, target)
  330.  
  331.         local LaserShotClone = BaseShot:Clone()
  332.         LaserShotClone.CFrame = ShotCFrame + (ShotCFrame.lookVector * (BaseShot.Size.Z / 2))
  333.         local BodyVelocity = Instance.new("BodyVelocity")
  334.         BodyVelocity.velocity = ShotCFrame.lookVector * Speed
  335.         BodyVelocity.Parent = LaserShotClone
  336.         LaserShotClone.Touched:connect(function(Hit)
  337.             if not Hit or not Hit.Parent then
  338.                 return
  339.             end
  340.             Touched(LaserShotClone, Hit)
  341.         end)
  342.         Debris:AddItem(LaserShotClone, Duration)
  343.         LaserShotClone.Parent = game:GetService("Workspace")
  344.  
  345.         wait(0.6) -- FireSound length
  346.  
  347.         InvokeClient("PlaySound", Sounds.Reload)
  348.  
  349.         wait(0.75) -- ReloadSound length
  350.  
  351.         Tool.Enabled = true
  352.     end
  353. end
  354.  
  355. function Unequipped()
  356.  
  357. end
  358.  
  359. BaseShot = Instance.new("Part")
  360. BaseShot.Name = "Effect"
  361. BaseShot.BrickColor = BrickColor.new("Really red")
  362. BaseShot.Material = Enum.Material.Plastic
  363. BaseShot.Shape = Enum.PartType.Block
  364. BaseShot.TopSurface = Enum.SurfaceType.Smooth
  365. BaseShot.BottomSurface = Enum.SurfaceType.Smooth
  366. BaseShot.FormFactor = Enum.FormFactor.Custom
  367. BaseShot.Size = Vector3.new(0.2, 0.2, 3)
  368. BaseShot.CanCollide = false
  369. BaseShot.Locked = true
  370. SelectionBoxify(BaseShot)
  371. Light(BaseShot)
  372. BaseShotSound = Sounds.HitFade:Clone()
  373. BaseShotSound.Parent = BaseShot
  374.  
  375. Tool.Equipped:connect(Equipped)
  376. Tool.Unequipped:connect(Unequipped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement