Heya, I’m trying to make a random weapon spawning system. Its fairly easy this is the script I have right now,
-- Weapon Spawn Variables
local weapons = game.ServerStorage.Weapons
local weaponSpawns = game.Workspace.GamePlay.WeaponSpawns:GetChildren()
local weaponSpawnsAmount = #weaponSpawns
-- Weapons Variables
local weaponsChildren = weapons:GetChildren()
local weaponCount = #weaponsChildren
local spawnRate = 30
for index, child in pairs(weaponSpawns) do -- Loop goes through each child of the weaponSpawns folder
-- Choses Weapons
local weaponChoice = math.random(1, #weaponsChildren)
print(weaponChoice)
if weaponChoice == 1 then -- Pistol
print("1 success")
local weapon = weapons.Glock:Clone()
weapon.Parent = child
weapon.Handle.CFrame = child.CFrame
elseif weaponChoice == 2 then -- AK47
print("2 success")
local weapon = weapons.AK:Clone()
weapon.Parent = child
weapon.Handle.CFrame = child.CFrame
elseif weaponChoice == 3 then -- Scar
print("3 success")
local weapon = weapons.Scar:Clone()
weapon.Parent = child
weapon.Handle.CFrame = child.CFrame
elseif weaponChoice == 4 then -- AWP
print("4 success")
local weapon = weapons.AWP:Clone()
weapon.Parent = child
weapon.Handle.CFrame = child.CFrame
end
end
print("there are "..weaponSpawnsAmount.." weapon spawns")
print("there are "..weaponCount.." current weapons")
The problem is that it only works for the glock. It wont parent any other tool to the WeaponSpawn, only the glock (if it chosen for that part). Heres some screenshots if your a lil confused, it should be working fine though?
It is printing stuff tho
(all of these WeaponSpawns should have Tools in them)