Advertisement
Guest User

GlobalFunctions

a guest
Jan 25th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. local GlobalFunctions = {}
  2.  
  3. --function for shooting a laser beam from a weapon tool
  4. function GlobalFunctions.shootLaser(player, mouseHit, tool, maxDistance, damage, color)
  5.     --create the ray itself from the tip to the position our mouse is clicking
  6.     local ray = Ray.new(tool.Tip.CFrame.p, (mouseHit.p - tool.Tip.CFrame.p).unit * maxDistance)
  7.     local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
  8.  
  9.     --create the look of the beam
  10.     local beam = Instance.new("Part", workspace)
  11.     beam.BrickColor = BrickColor.new(color)
  12.     beam.FormFactor = "Custom"
  13.     beam.Material = "Neon"
  14.     beam.Transparency = 0.25
  15.     beam.Anchored = true
  16.     beam.Locked = true
  17.     beam.CanCollide = false
  18.  
  19.     --cap the distance to the maxDistance value
  20.     local distance = (tool.Tip.CFrame.p - position).magnitude
  21.     if (distance > maxDistance) then
  22.         distance = maxDistance
  23.     end
  24.    
  25.     --change the size and direction of the beam
  26.     beam.Size = Vector3.new(0.3, 0.3, distance)
  27.     beam.CFrame = CFrame.new(tool.Tip.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
  28.  
  29.     --destroy the beam after some time
  30.     game:GetService("Debris"):AddItem(beam, 0.1)
  31.  
  32.     --check if part is hit and if the part belongs to a humanoid
  33.     if part then
  34.         local humanoid = part.Parent:FindFirstChild("Humanoid")
  35.         --check another parent level if it has a humanoid
  36.         if not humanoid then
  37.             local humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
  38.         end
  39.         --do damage if humanoid
  40.         if humanoid then
  41.             humanoid:TakeDamage(damage)
  42.         end
  43.     end
  44. end
  45.  
  46. return GlobalFunctions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement