Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Zombie spawner doesn't work as intended, why?

Asked by 1 year ago

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

0
.. theking66hayday 841 — 1y
0
Also forgot to mention try putting the pads in a folder and name it SpawnPad if that doesn't work name it to ZombieSpawns theking66hayday 841 — 1y
0
Rename folder to** theking66hayday 841 — 1y
0
Also can you maybe give me a screenshot? Upload your screenshot as a decal on Roblox and give me the link. theking66hayday 841 — 1y
View all comments (6 more)
0
I added a screenshot on your answer, it's from the Lightshot app SharkRayMaster 265 — 1y
0
Have you tried using break points and call stack to debug? Or maybe printing the tables? Flipstargamer 90 — 1y
0
Sorry, I don't know what break points and call stack are, I can try printing the table tho SharkRayMaster 265 — 1y
0
Nothing, it's printing what it's supposed to print, the table of spawnpads, Idk what to do anymore lol, is there any chance that it being a ModuleScript is making it break? because the spawn function is fired from another script, calling the Spawn Module Script SharkRayMaster 265 — 1y
0
probably try normal script theking66hayday 841 — 1y

1 answer

Log in to vote
1
Answered by 1 year ago

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!!

0
Also is there any errors theking66hayday 841 — 1y
0
Hey king, no, there is not any errors when I run my script, and when I use yours there is no errors either, but i checked and SpawnPad is equal to nil, I even changed "Pad" to the name of the part but still, doesn't work, plus every spawn part has a different name so having to enter it's name wont make it random, what could i do? SharkRayMaster 265 — 1y
0
Here is a picture If you'd like to see what happens: https://prnt.sc/lGzGRClA6Y5x SharkRayMaster 265 — 1y
0
You should have the spawnpads as named pad1. Make sure you keep upping the number by 1 theking66hayday 841 — 1y
View all comments (11 more)
0
Also might need to customize the code in this code block to work with your system theking66hayday 841 — 1y
0
Mhm, I did customize it, and the "pads" are all called "Spawner1, Spawner2, Spawner3" etc..., I'll try it again SharkRayMaster 265 — 1y
0
OK make sure you rename pads then in script theking66hayday 841 — 1y
0
It didn't work, this is killing my brain nothing seems to work and I don't know why SharkRayMaster 265 — 1y
0
mmmmm theking66hayday 841 — 1y
0
this is the last thing i can suggest theking66hayday 841 — 1y
0
Have you tried putting the spawnpads in a folder and naming the folder Spawnpad? Also try not having it in a folder unless if you already did tried that. theking66hayday 841 — 1y
0
Yea i did try that, but i'll try it again SharkRayMaster 265 — 1y
0
No, goddd, it doesn't work, I truly don't get why if im firing the GetRandomSpawnLocation() function 3 times, it chooses the same one for the 3 zombies. SharkRayMaster 265 — 1y
0
Very weird theking66hayday 841 — 1y
0
I have to think of more ideas theking66hayday 841 — 1y
Ad

Answer this question