Ok, so I've ran into a little bit of a problem, I'm making a zombie spawner script and the zombies do spawn, but instead of spawning in all the possible spawn locations (which are invisible Parts) they all spawn in the same one
This is the spawn
function:
function Commands.SpawnZombie(amount, class, safeMode) local zombieType = game.ReplicatedStorage.Zombies[class] for i = 1, amount do if safeMode == true then if game.ReplicatedStorage.ServerDetails.RoundActive == false then return end end local zombie = zombieType:Clone() zombie.Parent = game.Workspace.NPCs local RandomSpawnLocation = GetRandomSpawnLocation() zombie.PrimaryPart.CFrame = RandomSpawnLocation.CFrame end end
And this is the GetRandomSpawnLocation()
function:
function GetRandomSpawnLocation() local SpawnZones = game.Workspace.Map.SpawnZones:GetChildren() local randomSpawnZone = SpawnZones[math.random(1, #SpawnZones)] local SpawnLocations = randomSpawnZone:GetChildren() local RandomSpawnLocation = SpawnLocations[math.random(1, #SpawnLocations)] return RandomSpawnLocation end
A bit of information: The GetRandomSpawnLocation basically gets a random SpawnZone (which is a big part with alot of small parts inside it) then it gets a random SpawnLocation which are one of the small parts, and returns that location
But as i said, even tho im firing the function every loop, it still spawns them in the same place. why does this happen? please help :c
Maybe try the math random pads like this Example:
local pads = game.Workspace.ZombieSpawns local SpawnPad = pads:FindFirstChild("Pad"..math.random(1,#pads:GetChildren())) NewestPad:SetPrimaryPartCFrame(SpawnPad.CFrame + Vector3.new(0,3,0)) wait() NewestPad.Parent = workspace
You might need to edit it to your set up Hope this helps!!