So im trying to make a zombie spawn system that all the zombies don’t spawn into the same position. This is my script right now
game.Lighting.Changed:Connect(function()
if game.Lighting.ClockTime == 20 then
for count = 1,33 do
task.wait(1)
local clone = game.ReplicatedStorage.zombies.Zombie:Clone()
local folder = game.Workspace.ZombieSpawns:GetChildren()
local random = folder[math.random(1, 33)]
folder = game.Workspace.ZombieSpawns:GetChildren()
clone:MoveTo(random.Position)
clone.Parent = workspace
random.Parent = game.ReplicatedStorage.DisableSpawns
wait(1)
random = folder[math.random(1, 33)]
end
end
end)
game.Lighting.Changed:Connect(function()
if game.Lighting.ClockTime == 20 then
for count = 1,33 do
task.wait(1)
local clone = game.ReplicatedStorage.zombies.Zombie:Clone()
local folder = game.Workspace.ZombieSpawns:GetChildren()
local random = folder[math.random(1, 33)]
folder = game.Workspace.ZombieSpawns:GetChildren()
clone:SetPrimaryPartCFrame(random.CFrame)
clone.Parent = workspace
random.Parent = game.ReplicatedStorage.DisableSpawns
wait(1)
random = folder[math.random(1, 33)]
end
end
end)
ServerScriptService.SpawnZombie:9: attempt to index nil with 'CFrame'
It sometimes doesn’t give that error and works and other time it gives that error and breaks
game.Lighting.Changed:Connect(function()
if game.Lighting.ClockTime == 20 then
for count = 1,33 do
task.wait(1)
local clone = game.ReplicatedStorage.zombies.Zombie:Clone()
local folder = game.Workspace.ZombieSpawns:GetChildren()
local random = folder[math.random(1, #folder)]
folder = game.Workspace.ZombieSpawns:GetChildren()
clone:SetPrimaryPartCFrame(random.CFrame)
clone.Parent = workspace
random.Parent = game.ReplicatedStorage.DisableSpawns
wait(1)
random = folder[math.random(1, #folder)]
end
end
end)
Yeah, then the ‘random’ should have a CFrame by default. Try this new script.
Waitt I think I see the problem. Random is an operator (or something)
Use another variable.
game.Lighting.Changed:Connect(function()
if game.Lighting.ClockTime == 20 then
for count = 1,33 do
task.wait(1)
local clone = game.ReplicatedStorage.zombies.Zombie:Clone()
local folder = game.Workspace.ZombieSpawns:GetChildren()
local rng = folder[math.random(1, #folder)]
folder = game.Workspace.ZombieSpawns:GetChildren()
clone:SetPrimaryPartCFrame(rng.CFrame)
clone.Parent = workspace
rng.Parent = game.ReplicatedStorage.DisableSpawns
wait(1)
rng = folder[math.random(1, #folder)]
end
end
end)
this should do it lol
Just edited it because I made a typo, if it errors, try recopying this code