How do I fix it when the zombie spawn script duplicates the zombies. It happens after every second game I’m not sure why it duplicates.
On the first game it works normally but then on the second zombies spawn twice at the same time and I’m not sure what’s causing it.
Spawn Script:
script.Parent.Transparency = 1
local debounce = false
game.ReplicatedStorage.Events.spawnZombies.Event:Connect(function()
if debounce == false and script.Parent.ready.Value == true then
debounce = true
script.Parent.Transparency = 0
script.Parent.ParticleEmitter.Enabled = true
wait(3)
if script.Parent.zombieType.Value == "Zombie" then
local Rzombies = game:GetService("ReplicatedStorage").Zombies.RegularZombies:GetChildren()
local randomrZombie = Rzombies[math.random(1,#Rzombies)]:Clone()
randomrZombie.Parent = workspace.World
randomrZombie.HumanoidRootPart.CFrame = script.Parent.spawnPart.CFrame
script.Parent.Transparency = 1
script.Parent.ParticleEmitter.Enabled = false
end
if script.Parent.zombieType.Value == "Hunter" then
local Rzombies = game:GetService("ReplicatedStorage").Zombies.Hunter:GetChildren()
local randomrZombie = Rzombies[math.random(1,#Rzombies)]:Clone()
randomrZombie.Parent = workspace.World
randomrZombie.HumanoidRootPart.CFrame = script.Parent.spawnPart.CFrame
script.Parent.Transparency = 1
script.Parent.ParticleEmitter.Enabled = false
end
if script.Parent.zombieType.Value == "Boomer" then
local Rzombies = game:GetService("ReplicatedStorage").Zombies.Boomer:GetChildren()
local randomrZombie = Rzombies[math.random(1,#Rzombies)]:Clone()
randomrZombie.Parent = workspace.World
randomrZombie.Torso.CFrame = script.Parent.spawnPart.CFrame
script.Parent.Transparency = 1
script.Parent.ParticleEmitter.Enabled = false
end
if script.Parent.zombieType.Value == "FireZombie" then
local Rzombies = game:GetService("ReplicatedStorage").Zombies.FireZombie:GetChildren()
local randomrZombie = Rzombies[math.random(1,#Rzombies)]:Clone()
randomrZombie.Parent = workspace.World
randomrZombie.Torso.CFrame = script.Parent.spawnPart.CFrame
script.Parent.Transparency = 1
script.Parent.ParticleEmitter.Enabled = false
end
if script.Parent.zombieType.Value == "FireBoss" then
local Rzombies = game:GetService("ReplicatedStorage").Zombies.Bosses
local randomrZombie = Rzombies["Fire Boss"]:Clone()
randomrZombie.Parent = workspace.World
randomrZombie.Torso.CFrame = script.Parent.spawnPart.CFrame
script.Parent.Transparency = 1
script.Parent.ParticleEmitter.Enabled = false
end
script.Parent.ready.Value = false
wait(3)
debounce = false
end
end)
Here is the game script if that has anything to do with it:
local alivePlrs = {}
start_game_clone = game.Workspace.World:Clone()
start_game_clone.Parent = game.Lighting
function isEmpty(t)
for i, v in t do
return false
end
return true
end
game.ReplicatedStorage.Events.EndGame.Event:Connect(function()
game.ReplicatedStorage.Events.Zombies.Value = 0
script.Game.Value = false
game.ServerScriptService.Missions.Mission1.Story.Enabled = false
wait(0.1)
game.ServerScriptService.Missions.Mission1.Story.Enabled = true
print("Game Over")
for i,v in pairs(workspace.Music:GetChildren()) do
if v:IsA("Sound") then
v:Stop()
end
end
if game.ReplicatedStorage.Events.Win.Value == true then
else
workspace.Sound.GameOverSound:Play()
game.ReplicatedStorage.Events.GameOverText:FireAllClients("GAME OVER")
wait(8)
game.ReplicatedStorage.Events.GameOverText:FireAllClients("")
end
table.clear(alivePlrs)
wait(5)
workspace.World:Destroy()
wait(1)
game.Lighting.World:Clone().Parent = workspace
local newScript = script:Clone()
newScript.Parent = workspace
wait(0.1)
script:Destroy()
end)
game.Players.PlayerAdded:Connect(function(player)
local v = Instance.new("BoolValue")
v.Name = "Playing"
v.Parent = player
local v2 = Instance.new("BoolValue")
v2.Name = "Voted"
v2.Parent = player
end)
game.ReplicatedStorage.Events.voteMission.OnServerEvent:Connect(function(player, MissionValue, Mission)
Mission.Value = Mission.Value + 1
-- MissionValue.Number.Text = Mission.Value
wait(15)
game.ReplicatedStorage.Events.Mission1.Value = 0
game.ReplicatedStorage.Events.Mission2.Value = 0
game.ReplicatedStorage.Events.Mission3.Value = 0
end)
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
10, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
while true do
wait(5)
workspace.Music.LobbyMusic:Play()
game.ReplicatedStorage.Events.LobbyText:FireAllClients("The game will start soon..")
wait(10)
game.ReplicatedStorage.Events.LobbyText:FireAllClients("Voting will begin in")
wait(2)
game.ReplicatedStorage.Events.LobbyText:FireAllClients("3")
wait(1)
game.ReplicatedStorage.Events.LobbyText:FireAllClients("2")
wait(1)
game.ReplicatedStorage.Events.LobbyText:FireAllClients("1")
wait(1)
game.ReplicatedStorage.Events.LobbyText:FireAllClients(" ")
game.ReplicatedStorage.Events.voteScreen:FireAllClients()
wait(6)
game.ReplicatedStorage.Events.LobbyText:FireAllClients("Voting is about to end.")
wait(4)
game.ReplicatedStorage.Events.LobbyText:FireAllClients(" ")
game.ReplicatedStorage.Events.Fade:FireAllClients()
wait(4)
workspace.Music.LobbyMusic:Stop()
local Events = game.ReplicatedStorage.Events
if Events.Mission1.Value > Events.Mission2.Value and Events.Mission3.Value then
game.ReplicatedStorage.Events.Mission1Start:Fire()
end
if Events.Mission2.Value > Events.Mission1.Value and Events.Mission3.Value then
game.ReplicatedStorage.Events.Mission2Start:Fire()
end
if Events.Mission3.Value > Events.Mission1.Value and Events.Mission2.Value then
game.ReplicatedStorage.Events.Mission3Start:Fire()
end
if Events.Mission1.Value == Events.Mission2.Value and Events.Mission3.Value then
game.ReplicatedStorage.Events.Mission1Start:Fire()
end
script.Game.Value = true
for i, plr in pairs(game.Players:GetPlayers()) do
if plr.Character.Humanoid.Health == 0 then
if isEmpty(alivePlrs) then
game.ReplicatedStorage.Events.EndGame:Fire()
end
else
plr.Playing.Value = true
game.ReplicatedStorage.Events.Guns:Fire()
-- plr.Character.HumanoidRootPart.CFrame = workspace.TeleportDestination.CFrame
table.insert(alivePlrs, plr)
print(alivePlrs)
plr.Character.Humanoid.Died:Connect(function()
plr.Playing.Value = false
plr.Medic.Value = false
plr.Sheriff.Value = false
table.remove(alivePlrs, alivePlrs[plr])
print(alivePlrs)
if isEmpty(alivePlrs) then
game.ReplicatedStorage.Events.EndGame:Fire()
end
end)
end
end
game.Players.PlayerRemoving:Connect(function(plr)
print(plr.Name)
plr.Playing.Value = false
plr.Medic.Value = false
plr.Sheriff.Value = false
table.remove(alivePlrs, alivePlrs[plr])
print(alivePlrs)
if isEmpty(alivePlrs) then
game.ReplicatedStorage.Events.EndGame:Fire()
end
end)
wait(1293182391238123912312312313123)
end
Yeah so any help to fix it would be appreciated.