You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve?
to have it so the zombie spawners detect where the player is and set the zombie spawns to the closest part(s) nearby the player -
What is the issue?
the current zombie script grabs a table and randomizes the spawn locations. this works great in small maps however in larger maps the zombies could spawn on one side of the map while the player(s) is on the opposite site -
What solutions have you tried so far?
i tried looking through the DevForum but im not finding articles related to my issue, mostly chat distance or keybinding distance stuff.
so this script is what handles the zombie spawns. its quite large so iâll include the entire script as well as the section weâll be focusing on
entire script
local CS = game:getService("CollectionService")
while true do
wait(script.SpawnSpeed.Value)
for i, v in pairs(CS:GetTagged("spawner")) do
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
if game.ReplicatedStorage.Values.DogRound.Value == true then
if game.ReplicatedStorage.Values.dogroom1.Value == true then
local table = {
game.Workspace.DogSpawns.Part1,
game.Workspace.DogSpawns.Part2,
game.Workspace.DogSpawns.Part3,
game.Workspace.DogSpawns.Part4,
game.Workspace.DogSpawns.Part5,
game.Workspace.DogSpawns.Part6,
}
for i, v in ipairs(table) do
local random = math.random(1,6)
local doggiespawn = table[random]
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
doggiespawn.Loop:Play()
doggiespawn.Glow.Enabled = true
doggiespawn.ParticleEmitter.Enabled = true
wait(1.4)
v.Souls.Enabled = true
doggiespawn.Lightning:Play()
wait(0.4)
doggiespawn.Glow.Enabled = false
doggiespawn.ParticleEmitter.Enabled = false
doggiespawn.Union.Transparency = 0
wait(0.2)
doggiespawn.Union.Transparency = 1
local NPC3 = game.ReplicatedStorage.BOSS.Zombie:Clone()
NPC3.Parent = doggiespawn.Parent
NPC3.HumanoidRootPart.CFrame = doggiespawn.CFrame + Vector3.new(0, 2, 0)
CS:AddTag(NPC3, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
end
end
end
end
if game.ReplicatedStorage.Values.dogroom2.Value == true then
local table = {
game.Workspace.DogSpawns.Part1,
game.Workspace.DogSpawns.Part2,
game.Workspace.DogSpawns.Part3,
game.Workspace.DogSpawns.Part4,
game.Workspace.DogSpawns.Part5,
game.Workspace.DogSpawns.Part6,
game.Workspace.DogSpawns.Part7,
game.Workspace.DogSpawns.Part8,
game.Workspace.DogSpawns.Part9,
game.Workspace.DogSpawns.Part10,
game.Workspace.DogSpawns.Part11,
}
for i, v in ipairs(table) do
local random = math.random(1,11)
local doggiespawn = table[random]
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
doggiespawn.Loop:Play()
doggiespawn.Glow.Enabled = true
doggiespawn.ParticleEmitter.Enabled = true
wait(1.4)
v.Souls.Enabled = true
doggiespawn.Lightning:Play()
wait(0.4)
doggiespawn.Glow.Enabled = false
doggiespawn.ParticleEmitter.Enabled = false
doggiespawn.Union.Transparency = 0
wait(0.2)
doggiespawn.Union.Transparency = 1
local NPC3 = game.ReplicatedStorage.BOSS.Zombie:Clone()
NPC3.Parent = doggiespawn.Parent
NPC3.HumanoidRootPart.CFrame = doggiespawn.CFrame + Vector3.new(0, 2, 0)
CS:AddTag(NPC3, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
end
end
end
end
else
if game.ReplicatedStorage.Values.Zomroom1.Value == true then
local table = {
game.Workspace.ZomSpawn.spawner1,
game.Workspace.ZomSpawn.spawner2,
game.Workspace.ZomSpawn.spawner3,
game.Workspace.ZomSpawn.spawner4,
game.Workspace.ZomSpawn.spawner5,
game.Workspace.ZomSpawn.spawner6,
game.Workspace.ZomSpawn.spawner7,
game.Workspace.ZomSpawn.spawner8,
game.Workspace.ZomSpawn.spawner9,
game.Workspace.ZomSpawn.spawner10,
game.Workspace.ZomSpawn.spawner11,
}
for i, v in ipairs(table) do
local random = math.random(1,11)
local ZomSpawn = table[random]
local sound1 = ZomSpawn:WaitForChild("sound1")
local sound2 = ZomSpawn:WaitForChild("sound2")
local sounds = {sound1, sound2}
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
sounds[math.random(1, #sounds)]:Play()
ZomSpawn.D1.Enabled = true
ZomSpawn.D2.Enabled = true
wait(1)
ZomSpawn.D1.Enabled = false
ZomSpawn.D2.Enabled = false
local NPC = game.ServerStorage.Zombie:Clone()
NPC.Parent = game.Workspace.Zombies
NPC.HumanoidRootPart.CFrame = ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
NPC.HumanoidRootPart.Anchored = true
CS:AddTag(NPC, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
wait(0.5)
end
end
end
end
if game.ReplicatedStorage.Values.Zomroom2.Value == true then
local table = {
game.Workspace.ZomSpawn.spawner1,
game.Workspace.ZomSpawn.spawner2,
game.Workspace.ZomSpawn.spawner3,
game.Workspace.ZomSpawn.spawner4,
game.Workspace.ZomSpawn.spawner5,
game.Workspace.ZomSpawn.spawner6,
game.Workspace.ZomSpawn.spawner7,
game.Workspace.ZomSpawn.spawner8,
game.Workspace.ZomSpawn.spawner9,
game.Workspace.ZomSpawn.spawner10,
game.Workspace.ZomSpawn.spawner11,
game.Workspace.ZomSpawn.spawner12,
game.Workspace.ZomSpawn.spawner13,
game.Workspace.ZomSpawn.spawner14,
game.Workspace.ZomSpawn.spawner15,
game.Workspace.ZomSpawn.spawner16,
game.Workspace.ZomSpawn.spawner17,
}
for i, v in ipairs(table) do
local random = math.random(1,17)
local ZomSpawn = table[random]
local sound1 = ZomSpawn:WaitForChild("sound1")
local sound2 = ZomSpawn:WaitForChild("sound2")
local sounds = {sound1, sound2}
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
sounds[math.random(1, #sounds)]:Play()
ZomSpawn.D1.Enabled = true
ZomSpawn.D2.Enabled = true
wait(1)
ZomSpawn.D1.Enabled = false
ZomSpawn.D2.Enabled = false
local NPC = game.ServerStorage.Zombie:Clone()
NPC.Parent = game.Workspace.Zombies
NPC.HumanoidRootPart.CFrame = ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
NPC.HumanoidRootPart.Anchored = true
CS:AddTag(NPC, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
wait(0.5)
end
end
end
end
if game.ReplicatedStorage.Values.Zomroom3.Value == true then
local table = {
game.Workspace.ZomSpawn.spawner1,
game.Workspace.ZomSpawn.spawner2,
game.Workspace.ZomSpawn.spawner3,
game.Workspace.ZomSpawn.spawner4,
game.Workspace.ZomSpawn.spawner5,
game.Workspace.ZomSpawn.spawner6,
game.Workspace.ZomSpawn.spawner7,
game.Workspace.ZomSpawn.spawner8,
game.Workspace.ZomSpawn.spawner9,
game.Workspace.ZomSpawn.spawner10,
game.Workspace.ZomSpawn.spawner11,
game.Workspace.ZomSpawn.spawner12,
game.Workspace.ZomSpawn.spawner13,
game.Workspace.ZomSpawn.spawner14,
game.Workspace.ZomSpawn.spawner15,
game.Workspace.ZomSpawn.spawner16,
game.Workspace.ZomSpawn.spawner17,
game.Workspace.ZomSpawn.spawner18,
game.Workspace.ZomSpawn.spawner19,
}
for i, v in ipairs(table) do
local random = math.random(1,18)
local ZomSpawn = table[random]
local sound1 = ZomSpawn:WaitForChild("sound1")
local sound2 = ZomSpawn:WaitForChild("sound2")
local sounds = {sound1, sound2}
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
sounds[math.random(1, #sounds)]:Play()
ZomSpawn.D1.Enabled = true
ZomSpawn.D2.Enabled = true
wait(1)
ZomSpawn.D1.Enabled = false
ZomSpawn.D2.Enabled = false
local NPC = game.ServerStorage.Zombie:Clone()
NPC.Parent = game.Workspace.Zombies
NPC.HumanoidRootPart.CFrame = ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
NPC.HumanoidRootPart.Anchored = true
CS:AddTag(NPC, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
wait(0.5)
end
end
end
end
local table = {
game.Workspace.ZomSpawn.spawner1,
game.Workspace.ZomSpawn.spawner2,
game.Workspace.ZomSpawn.spawner3,
game.Workspace.ZomSpawn.spawner4,
game.Workspace.ZomSpawn.spawner5,
game.Workspace.ZomSpawn.spawner6,
}
for i, v in ipairs(table) do
local random = math.random(1,6)
local ZomSpawn = table[random]
local sound1 = ZomSpawn:WaitForChild("sound1")
local sound2 = ZomSpawn:WaitForChild("sound2")
local sounds = {sound1, sound2}
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
sounds[math.random(1, #sounds)]:Play()
ZomSpawn.D1.Enabled = true
ZomSpawn.D2.Enabled = true
wait(1)
ZomSpawn.D1.Enabled = false
ZomSpawn.D2.Enabled = false
local NPC = game.ServerStorage.Zombie:Clone()
NPC.Parent = game.Workspace.Zombies
NPC.HumanoidRootPart.CFrame = ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
NPC.HumanoidRootPart.Anchored = true
CS:AddTag(NPC, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
wait(0.5)
end
end
end
end
end
end
end
end
its large due to it checking if player has opened doors to new âroomsâ (areas) and adding spawn locations into the randomizer. it also checks if its on a dog round aswell as the âroomsâ available to spawn in.
also the tagged âSpawnersâ is how i used to handle the spawning locations but as of yesterday im experimenting with this new spawning functionality
(previous one would have all the zombies spawn in at tagged locations of âspawnâ all at once. this new way makes it randomized as well as a bit cleaner in having each location having effects/SFX and more performance friendly instead of having 30+ humanoids cloned into the map all at once)
again this works great in a small scale map, however in a big map it can cause long round times.
to make things easier lets focus on this area:
local table = {
game.Workspace.ZomSpawn.spawner1,
game.Workspace.ZomSpawn.spawner2,
game.Workspace.ZomSpawn.spawner3,
game.Workspace.ZomSpawn.spawner4,
game.Workspace.ZomSpawn.spawner5,
game.Workspace.ZomSpawn.spawner6,
}
for i, v in ipairs(table) do
local random = math.random(1,6)
local ZomSpawn = table[random]
local sound1 = ZomSpawn:WaitForChild("sound1")
local sound2 = ZomSpawn:WaitForChild("sound2")
local sounds = {sound1, sound2}
if game.ReplicatedStorage.Values.zombiesRemaining.Value > 0 and game.ReplicatedStorage.Values.zombiesOnScreen.Value < game.ReplicatedStorage.Values.zombieLimit.Value then
if game.ReplicatedStorage.Values.gameInProgress.Value == true then
sounds[math.random(1, #sounds)]:Play()
ZomSpawn.D1.Enabled = true
ZomSpawn.D2.Enabled = true
wait(1)
ZomSpawn.D1.Enabled = false
ZomSpawn.D2.Enabled = false
local NPC = game.ServerStorage.Zombie:Clone()
NPC.Parent = game.Workspace.Zombies
NPC.HumanoidRootPart.CFrame = ZomSpawn.CFrame + Vector3.new(0, 2.5, 0)
NPC.HumanoidRootPart.Anchored = true
CS:AddTag(NPC, "Zombie")
game.ReplicatedStorage.Values.zombiesRemaining.Value = game.ReplicatedStorage.Values.zombiesRemaining.Value - 1
wait(0.5)
So, i am wondering if theres a way to detect if a player is nearby one of the zombies spawners and make it so the other spawners are inactive.
feedback is much appreciated, im still learning the LUA language