Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | None | 0 0
  1. local GlobalFunctions = {}
  2.  
  3. --SpawnWeapon function that randomly selects a weapon from server storage to spawn
  4. function GlobalFunctions.spawnWeapon(part)
  5.     --table list of all weapons
  6.     local weapons = game.ServerStorage.Weapons:GetChildren()
  7.    
  8.     --variables to select the random weapon to spawn
  9.     local numMax = table.getn(weapons)
  10.     local num = math.random(1,numMax)
  11.     local weaponToSpawn = weapons[num]
  12.    
  13.     --clone variable of weapon to spawn
  14.     local weaponClone = weaponToSpawn:Clone()
  15.    
  16.     --for loop that goes through the whole weapon moving all of its parts to the
  17.     --position of the part you specified
  18.     for i, weaponPart in ipairs(weaponClone:GetChildren()) do
  19.         if weaponPart:IsA("BasePart") then
  20.             weaponPart.Position = part.Position
  21.         end
  22.     end
  23.    
  24.     --move this newly cloned weapon to the Weapons folder for organization
  25.     weaponClone.Parent = workspace.Weapons
  26. end
  27.  
  28. --function for shooting a laser beam from a weapon tool
  29. function GlobalFunctions.shootLaser(player, mouseHit, tool, maxDistance, damage, color)
  30.     --create the ray itself from the tip to the position our mouse is clicking
  31.     local ray = Ray.new(tool.Tip.CFrame.p, (mouseHit.p - tool.Tip.CFrame.p).unit * maxDistance)
  32.     local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
  33.  
  34.     --create the look of the beam
  35.     local beam = Instance.new("Part", workspace)
  36.     beam.BrickColor = BrickColor.new(color)
  37.     beam.FormFactor = "Custom"
  38.     beam.Material = "Neon"
  39.     beam.Transparency = 0.25
  40.     beam.Anchored = true
  41.     beam.Locked = true
  42.     beam.CanCollide = false
  43.  
  44.     --cap the distance to the maxDistance value
  45.     local distance = (tool.Tip.CFrame.p - position).magnitude
  46.     if (distance > maxDistance) then
  47.         distance = maxDistance
  48.     end
  49.    
  50.     --change the size and direction of the beam
  51.     beam.Size = Vector3.new(0.3, 0.3, distance)
  52.     beam.CFrame = CFrame.new(tool.Tip.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
  53.  
  54.     --destroy the beam after some time
  55.     game:GetService("Debris"):AddItem(beam, 0.1)
  56.  
  57.     --check if part is hit and if the part belongs to a humanoid
  58.     if part then
  59.         local humanoid = part.Parent:FindFirstChild("Humanoid")
  60.         --check another parent level if it has a humanoid
  61.         if not humanoid then
  62.             local humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
  63.         end
  64.         --do damage if humanoid
  65.         if humanoid then
  66.             humanoid:TakeDamage(damage)
  67.         end
  68.     end
  69. end
  70.  
  71. return GlobalFunctions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement