Advertisement
InTesting

Better E Laser

Sep 8th, 2019
446
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 15.20 KB | None | 0 0
  1. print'https://pastebin.com/A3LTyBrB'
  2. --// Why is this better? it recycles the laser and sound.
  3. local function Get_Components_Of_Mouse(player)
  4.     local pchar = player.Character
  5.     if pchar then
  6.         local Remote = pchar:FindFirstChild('RE_Mouse')or
  7.             Instance.new("RemoteEvent",pchar)
  8.         Remote.Name = 'RE_Mouse'
  9.        
  10.         Remote.Parent = NLS(
  11.             [[
  12. local lp,runs,re =
  13.     game:GetService'Players'.LocalPlayer,game:GetService'RunService',
  14.     script:WaitForChild('RE_Mouse')
  15. local mouse = lp:GetMouse()
  16.  
  17. mouse.KeyDown:Connect(function(k)
  18.     re:FireServer('KeyDown',k,mouse.Hit)
  19. end)
  20.             ]]
  21.             ,pchar)
  22.         return Remote
  23.     else
  24.         error('Best to actually put your character In the game.')
  25.     end
  26. end
  27. local re = Get_Components_Of_Mouse(owner)
  28. local person = owner.Character
  29. local deb = game:GetService("Debris")
  30. local head = person:WaitForChild'Head'
  31. local _ = person:WaitForChild'HumanoidRootPart'
  32. local _ = person:WaitForChild'Humanoid'
  33.  
  34. -- // Weapons Closet \\ --
  35.  
  36. local function Damage(part)
  37.     --[[
  38.         // Description \\
  39.         This Function can damage a model with a given part. The default damage is 10,
  40.         and can not be adjusted If its replacing an unnamed Function in an event.
  41.         So it's best advised to change the
  42.         local varables within the Function. If a humanoid is not found, the model will
  43.         be killed.
  44.        
  45.         Local varables:
  46.             (Number) Kill_At_LargeHealth
  47.                 Automatically kills player if the humanoid's health is atleast of
  48.                 this number. If the number is 0, Then it does nothing.
  49.             (Number) Damage_humanoid
  50.                 Amount of damage towards the humanoid.
  51.     --]]
  52.     local Kill_At_LargeHealth = 100
  53.     local Damage_humanoid = 10
  54.     pcall(function()
  55.         local mod = part:FindFirstAncestorWhichIsA'Model'
  56.         if mod then
  57.             if mod~=workspace then
  58.                 local hum = mod:FindFirstChildWhichIsA'Humanoid'
  59.                 local target = mod:FindFirstChild'Head'or mod:FindFirstChild'Torso'or mod:FindFirstChild'UpperTorso'or mod:FindFirstChild'HumanoidRootPart'
  60.                 if hum then
  61.                     if hum.Health>Kill_At_LargeHealth and Kill_At_LargeHealth~=0 then
  62.                         hum.Health = 0
  63.                     else
  64.                         if hum.Health>0 then
  65.                             hum:TakeDamage(Damage_humanoid)
  66.                         end
  67.                     end
  68.                 elseif target then
  69.                     target:Destroy()
  70.                 else
  71.                     mod:BreakJoints()
  72.                 end
  73.             end
  74.         end
  75.     end)
  76. end
  77. local function CustomDamage(part,damage,Kill_At_Large_Health,noharm)
  78.     --[[
  79.         // Description \\
  80.         Similar to Damage() except you can not use it to replace an unamed Function
  81.         in an event, but this version has parameters.
  82.        
  83.         --> Manatory
  84.             (Instance) Part the Function will be checking.
  85.             (Number) Amount of damage.
  86.         --> Optional
  87.             (Number) Amount of health that a player needs in order to be automatically
  88.             killed.
  89.                 Default =
  90.                     0
  91.             (Instance) The Instance that the Function will be ignoring.
  92.                 Default =
  93.                     nil
  94.     --]]
  95.     if not Kill_At_Large_Health then
  96.         Kill_At_Large_Health = 0
  97.     end
  98.     pcall(function()
  99.         local mod = part:FindFirstAncestorWhichIsA'Model'
  100.         if mod then
  101.             if mod~=workspace then
  102.                 local bool = true
  103.                 if noharm then
  104.                     if noharm==mod then
  105.                         bool = false
  106.                     end
  107.                 end
  108.                 if bool then
  109.                     local hum = mod:FindFirstChildWhichIsA'Humanoid'
  110.                     local target = mod:FindFirstChild'Head'or mod:FindFirstChild'Torso'or mod:FindFirstChild'UpperTorso'or mod:FindFirstChild'HumanoidRootPart'
  111.                     if hum then
  112.                         if hum.Health>100 then
  113.                             hum.Health = 0
  114.                         else
  115.                             if hum.Health>0 then
  116.                                 hum:TakeDamage(damage)
  117.                             end
  118.                         end
  119.                     elseif target then
  120.                         target:Destroy()
  121.                     else
  122.                         mod:BreakJoints()
  123.                     end
  124.                 end
  125.             end
  126.         end
  127.     end)
  128. end
  129. local function Explosion_Effect(hit,bullet,noharm,damage,part_properties,end_size,tw_info,
  130. end_properties)
  131.     --[[
  132.         // Description \\
  133.         Explosion on hit.
  134.        
  135.         M hit (Instance) Part that's the target part.
  136.         O
  137.     --]]
  138.     local function Check_Parameter(para,def)
  139.         if para then
  140.             if typeof(para)==typeof(def)then
  141.                 return para
  142.             end
  143.         end
  144.         return def
  145.     end
  146.    
  147. end
  148.  
  149. local function Laser_Beam(Start_Pos,End_Cframe,part_properties,beam_width,damage,
  150. delay_damage,noharm,duration)
  151.     --[[
  152.         // Description \\
  153.         Returns part that will mimic a laser beam. Often Varies from the style.
  154.         Best to keep the laser beam as a block and not a cylinder.
  155.        
  156.         Note theres alot of parameters so bare with me.
  157.        
  158.         M = Manatory
  159.         O = Optional
  160.        
  161.         M Start_Pos (Vector3) Position where the laser is starting.
  162.         M End_Cframe (CFrame) Needed to find the size of laser's length and the
  163.             End point.
  164.         O part_properties (Table) Properties of the laser. Use the format:
  165.                
  166.                 Property = value
  167.                
  168.             Default =
  169.                 (A typical brick except:)
  170.                
  171.                     Anchored = true,
  172.                     Parent = nil
  173.                
  174.         O beam_width (Number) The width and height of the laser.
  175.             Default =
  176.                 .1
  177.         O damage (Number) The amount of damage it will deal.
  178.             Default =
  179.                 10
  180.         O delay_damage (Number) Delay in seconds for the laser to rest.
  181.             Default =
  182.                 .1
  183.         O noharm (Instance) Instance for the noharm argument in CustomDamage(). Basically
  184.             ignores the model if the part it hits is a descendant of it.
  185.             Default =
  186.                 nil
  187.         O duration (Number) Amount in seconds before it disappears.
  188.             Default =
  189.                 1
  190.     --]]
  191.  
  192.     local part = Instance.new("Part")
  193.    
  194.     local function Check_Parameter(parameter,default)
  195.         if parameter then
  196.             if typeof(parameter)==typeof(default)then
  197.                 return parameter
  198.             else
  199.                 return default
  200.             end
  201.         else
  202.             return default
  203.         end
  204.     end
  205.     beam_width = Check_Parameter(beam_width,.1)
  206.     damage = Check_Parameter(damage,10)
  207.     delay_damage = Check_Parameter(delay_damage,.1)
  208.     duration = Check_Parameter(duration,1)
  209.    
  210.     local diff = (Start_Pos - End_Cframe.Position).Magnitude
  211.     for i,v in pairs(part_properties)do
  212.         pcall(function()
  213.             part[i] = v
  214.         end)
  215.     end
  216.     part.Anchored = true
  217.     part.CFrame = CFrame.new(Start_Pos,End_Cframe.Position) * CFrame.new(0,0,-diff/2)
  218.     part.Size = Vector3.new(beam_width,beam_width,diff)
  219.     local bool = true
  220.     part.Touched:Connect(function(h)
  221.         if bool then
  222.             bool = false
  223.             CustomDamage(h,damage,nil,noharm)
  224.             wait(delay_damage)
  225.             bool = true
  226.         end
  227.     end)
  228.    
  229.    
  230.     if duration then
  231.         local debris = game:GetService("Debris")
  232.         debris:AddItem(part,duration)
  233.     end
  234.    
  235.     return part
  236. end
  237. local function Bullet_Beam(Start_Pos,End_Cframe,part_properties,beam_width,damage,
  238.     delay_damage,bullet_length,type_of_travel,noharm,is_spawned,for_loop_steps,
  239.     for_loop_stud_step_forward,for_loop_stud_step_delay,tw_info,effect_function)
  240.  
  241.     --[[
  242.         // Description \\
  243.         Fuck these parameters. I'm gonna make a simpler version some day.
  244.        
  245.         Returns a bullet. Note this can auto launch if you want to.
  246.        
  247.         M = Manatory
  248.         O = Optional
  249.    
  250.         M Start_Pos (Vector3) Position where the bullet starts.
  251.         M End_Cframe (CFrame) Necessary for the End Point of the bullet and the
  252.             direction.
  253.         O part_properties (Table) Table of properties for the bullet.
  254.             Default =
  255.                 Most of the properties of a typical part.
  256.         O beam_width (Number) The width and height of the bullet.
  257.             Default =
  258.                 .1
  259.         O damage (Number) The Damage it will deal.
  260.             Default =
  261.                 10
  262.         O delay_damage (Number) The delay of the bullet's damage
  263.             Default =
  264.                 1
  265.         O bullet_length (Number) The length of the bullet.
  266.             Default =
  267.                 .25
  268.         O type_of_travel (String) The Mode of travel:
  269.              - 'for_loop'; This mode will look laggy and will use a for loop.
  270.              - 'tween'; This mode will look smoother if in small servers and uses
  271.                 Tweenservice.
  272.              - (Default) nil
  273.             Note this will affect other parameters.
  274.         O noharm (Instance) Parameter for CustomDamage()
  275.             Default =
  276.                 nil
  277.         O (type_of_travel~=nil) is_spawned (Boolean) Makes a new thread for the
  278.             travel Function, If [type_of_travel] is not nil. In skid
  279.             language, it will prevent the script from yielding/pause the script.
  280.             Default =
  281.                 nil/false
  282.         O (type_of_travel~=nil) for_loop_steps (Number)
  283.             in type_of_travel=='for_loop', this number will be of how many times the
  284.                 bullet will phase through [for_loop_stud_step_forward] of studs.
  285.            
  286.             in type_of_travel=='tween', this number will be multiplied with
  287.                 [for_loop_stud_step_forward] to create the End point of the bullet.
  288.                
  289.             Default =
  290.                 10
  291.            
  292.         O (type_of_travel~=nil) for_loop_stud_step_forward (Number)
  293.             in type_of_travel=='for_loop', this number will be the amount of studs that
  294.                 it will go through per phase.
  295.                
  296.             in type_of_travel=='tween', this number will be multiplied with
  297.                 [for_loop_steps] to create the End point of the bullet.
  298.            
  299.             Default =
  300.                 1
  301.         O (type_of_travel=='for_loop') for_loop_stud_step_delay (Number)
  302.             This number will be the amout in seconds the bullet will pause before it
  303.             goes through another phase.
  304.            
  305.             Note this does not apply to (type_of_travel=='tween') because tween is
  306.             based so that the bullet will travel to its End Position.
  307.             (type_of_travel=='for_loop') is based so that it phases after a certiain
  308.             amount of numbers.
  309.            
  310.             Default =
  311.                 .1
  312.         O (type_of_travel=='tween') tw_info (TweenInfo)
  313.             This will determine the time, and Enum.EasingStyle it will use.
  314.             Default =
  315.                 TweenInfo.new(1,Enum.EasingStyle.Linear,
  316.                 Enum.EasingDirection.InOut,0,false,0)
  317.         O effect_function (Function)
  318.             Function when bullet hits a part.
  319.             Default =
  320.                 CustomDamage()
  321.        
  322.     --]]
  323.  
  324.     local part = Instance.new("Part")
  325.     local travel
  326.     local diff = (Start_Pos - End_Cframe.Position).Magnitude
  327.    
  328.     local function Check_Parameter(parameter,default)
  329.         if parameter then
  330.             if typeof(parameter)==typeof(default)then
  331.                 return parameter
  332.             else
  333.                 return default
  334.             end
  335.         else
  336.             return default
  337.         end
  338.     end
  339.     beam_width = Check_Parameter(beam_width,.1)
  340.     damage = Check_Parameter(damage,10)
  341.     delay_damage = Check_Parameter(delay_damage,.1)
  342.     bullet_length = Check_Parameter(bullet_length,.25)
  343.     for_loop_steps = Check_Parameter(for_loop_steps,10)
  344.     for_loop_stud_step_forward = Check_Parameter(for_loop_stud_step_forward,1)
  345.     for_loop_stud_step_delay = Check_Parameter(for_loop_stud_step_delay,.1)
  346.     tw_info = Check_Parameter(tw_info,TweenInfo.new(1,Enum.EasingStyle.Linear,
  347.                     Enum.EasingDirection.InOut,0,false,0))
  348.    
  349.     for i,v in pairs(part_properties)do
  350.         pcall(function()
  351.             part[i] = v
  352.         end)
  353.     end
  354.     part.Anchored = true
  355.     part.CFrame = CFrame.new(Start_Pos,End_Cframe.Position)
  356.     part.Size = Vector3.new(beam_width,beam_width,bullet_length)
  357.     local bool = true
  358.     part.Touched:Connect(function(h)
  359.         if bool then
  360.             bool = false
  361.             if not effect_function then
  362.                 CustomDamage(h,damage,nil,noharm)
  363.             else
  364.                 effect_function(h,part,noharm)
  365.             end
  366.             wait(delay_damage)
  367.             bool = true
  368.         end
  369.     end)
  370.    
  371.     if type_of_travel=='for_loop'then
  372.         travel = function()
  373.             for i=1,for_loop_steps do
  374.                 part.CFrame = part.CFrame *
  375.                     CFrame.new(0,0,-for_loop_stud_step_forward)
  376.                 wait(for_loop_stud_step_delay)
  377.             end
  378.             part.Anchored = false
  379.             part.CanCollide = false
  380.         end
  381.     elseif type_of_travel=='tween'then
  382.         travel = function()
  383.             local tws = game:GetService("TweenService")
  384.             local prop = {
  385.                 CFrame = part.CFrame * CFrame.new(0,0,-(for_loop_steps * for_loop_stud_step_forward))
  386.                 }
  387.             local an = tws:Create(part,tw_info,prop)
  388.             an:Play()
  389.             wait(an.TweenInfo.Time)
  390.             part.Anchored = false
  391.             part.CanCollide = false
  392.         end
  393.     end
  394.     if travel then
  395.         if is_spawned then
  396.             spawn(travel)
  397.         else
  398.             travel()
  399.         end
  400.     end
  401.    
  402.     return part
  403. end
  404. local function Laser_Beam_Cylinder(Start_Pos,End_Cframe,part_properties,beam_width,damage,
  405. delay_damage,noharm,duration)
  406.     --[[
  407.         // Description \\
  408.         Returns part that will mimic a laser beam. Often Varies from the style.
  409.         Best to keep the laser beam as a block and not a cylinder.
  410.        
  411.         Note theres alot of parameters so bare with me.
  412.        
  413.         M = Manatory
  414.         O = Optional
  415.        
  416.         M Start_Pos (Vector3) Position where the laser is starting.
  417.         M End_Cframe (CFrame) Needed to find the size of laser's length and the
  418.             End point.
  419.         O part_properties (Table) Properties of the laser. Use the format:
  420.                
  421.                 Property = value
  422.                
  423.             Default =
  424.                 (A typical brick except:)
  425.                
  426.                     Anchored = true,
  427.                     Parent = nil
  428.                
  429.         O beam_width (Number) The width and height of the laser.
  430.             Default =
  431.                 .1
  432.         O damage (Number) The amount of damage it will deal.
  433.             Default =
  434.                 10
  435.         O delay_damage (Number) Delay in seconds for the laser to rest.
  436.             Default =
  437.                 .1
  438.         O noharm (Instance) Instance for the noharm argument in CustomDamage(). Basically
  439.             ignores the model if the part it hits is a descendant of it.
  440.             Default =
  441.                 nil
  442.         O duration (Number) Amount in seconds before it disappears.
  443.             Default =
  444.                 1
  445.     --]]
  446.  
  447.     local part = Instance.new("Part")
  448.    
  449.     local function Check_Parameter(parameter,default)
  450.         if parameter then
  451.             if typeof(parameter)==typeof(default)then
  452.                 return parameter
  453.             else
  454.                 return default
  455.             end
  456.         else
  457.             return default
  458.         end
  459.     end
  460.     beam_width = Check_Parameter(beam_width,.1)
  461.     damage = Check_Parameter(damage,10)
  462.     delay_damage = Check_Parameter(delay_damage,.1)
  463.  
  464.    
  465.     local diff = (Start_Pos - End_Cframe.Position).Magnitude
  466.     for i,v in pairs(part_properties)do
  467.         pcall(function()
  468.             part[i] = v
  469.         end)
  470.     end
  471.     part.Shape = 'Cylinder'
  472.     part.Anchored = true
  473.     part.CFrame = CFrame.new(Start_Pos,End_Cframe.Position) * CFrame.new(0,0,-diff/2)
  474.     * CFrame.Angles(math.rad(90),0,math.rad(90))
  475.     part.Size = Vector3.new(diff,beam_width,beam_width)
  476.     local bool = true
  477.     part.Touched:Connect(function(h)
  478.         if bool then
  479.             bool = false
  480.             CustomDamage(h,damage,nil,noharm)
  481.             wait(delay_damage)
  482.             bool = true
  483.         end
  484.     end)
  485.    
  486.    
  487.     if duration then
  488.         local debris = game:GetService("Debris")
  489.         debris:AddItem(part,duration)
  490.     end
  491.    
  492.     return part
  493. end
  494.  
  495.  
  496. local function On_OnServerEvent(player,...)
  497.     local parameters = {...}
  498.     if parameters[1]=='KeyDown'and true then -- player==owner
  499.         if parameters[2]=='e'and parameters[3]then
  500.             local pchar = player.Character
  501.             local folder = pchar:FindFirstChild'Lasers'or (function()
  502.                     local a = Instance.new("Folder");a.Name='Lasers';
  503.                     a.Parent=pchar;return a
  504.             end)()
  505.             local Start_Pos,End_Cframe,beam_width =
  506.                 head.Position + Vector3.new(0,5,0),parameters[3],1
  507.             local beam = folder:FindFirstChild'Beam'or
  508.                 Laser_Beam_Cylinder(Start_Pos,End_Cframe,{Parent=folder,
  509.                 Name='Beam',Material='ForceField',CanCollide=false,
  510.                 BrickColor = BrickColor.new("Really red")},
  511.                 beam_width,100,.25,person)
  512.            
  513.             local diff = (Start_Pos - End_Cframe.Position).Magnitude
  514.             beam.CFrame = CFrame.new(Start_Pos,End_Cframe.Position)*
  515.                 CFrame.new(0,0,-diff/2)*
  516.                 CFrame.Angles(math.rad(90),0,math.rad(90))
  517.                 beam.Size = Vector3.new(diff,beam_width,beam_width)
  518.             local block = folder:FindFirstChild'Block'or(function()
  519.                 local b=Instance.new("Part");b.Size=Vector3.new(5,5,5);
  520.                 b.BrickColor=BrickColor.new("Really red");b.Anchored=true;
  521.                 b.Name = 'Block';b.CanCollide=false;b.Material='ForceField';
  522.                 b.Parent=folder;return b
  523.             end)()
  524.             block.CFrame = CFrame.new(Start_Pos,End_Cframe.Position)
  525.             local Sound = block:FindFirstChildWhichIsA'Sound'or(function()
  526.                 local s=Instance.new("Sound");s.SoundId='rbxassetid://2544621925';
  527.                 s.Parent=block;s.Volume=2.5;return s
  528.             end)()
  529.             Sound:Play()
  530.         end
  531.     end
  532. end
  533.  
  534.  
  535.  
  536. re.OnServerEvent:Connect(On_OnServerEvent)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement