Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local GlobalFunctions = {}
- --SpawnWeapon function that randomly selects a weapon from server storage to spawn
- function GlobalFunctions.spawnWeapon(part)
- --table list of all weapons
- local weapons = game.ServerStorage.Weapons:GetChildren()
- --variables to select the random weapon to spawn
- local numMax = table.getn(weapons)
- local num = math.random(1,numMax)
- local weaponToSpawn = weapons[num]
- --clone variable of weapon to spawn
- local weaponClone = weaponToSpawn:Clone()
- --for loop that goes through the whole weapon moving all of its parts to the
- --position of the part you specified
- for i, weaponPart in ipairs(weaponClone:GetChildren()) do
- if weaponPart:IsA("BasePart") then
- weaponPart.Position = part.Position
- end
- end
- --move this newly cloned weapon to the Weapons folder for organization
- weaponClone.Parent = workspace.Weapons
- end
- --function for shooting a laser beam from a weapon tool
- function GlobalFunctions.shootLaser(player, mouseHit, tool, maxDistance, damage, color)
- --create the ray itself from the tip to the position our mouse is clicking
- local ray = Ray.new(tool.Tip.CFrame.p, (mouseHit.p - tool.Tip.CFrame.p).unit * maxDistance)
- local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
- --create the look of the beam
- local beam = Instance.new("Part", workspace)
- beam.BrickColor = BrickColor.new(color)
- beam.FormFactor = "Custom"
- beam.Material = "Neon"
- beam.Transparency = 0.25
- beam.Anchored = true
- beam.Locked = true
- beam.CanCollide = false
- --cap the distance to the maxDistance value
- local distance = (tool.Tip.CFrame.p - position).magnitude
- if (distance > maxDistance) then
- distance = maxDistance
- end
- --change the size and direction of the beam
- beam.Size = Vector3.new(0.3, 0.3, distance)
- beam.CFrame = CFrame.new(tool.Tip.CFrame.p, position) * CFrame.new(0, 0, -distance/2)
- --destroy the beam after some time
- game:GetService("Debris"):AddItem(beam, 0.1)
- --check if part is hit and if the part belongs to a humanoid
- if part then
- local humanoid = part.Parent:FindFirstChild("Humanoid")
- --check another parent level if it has a humanoid
- if not humanoid then
- local humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
- end
- --do damage if humanoid
- if humanoid then
- humanoid:TakeDamage(damage)
- end
- end
- end
- return GlobalFunctions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement