Code issues - Random Spawn "Zombie"

Hello I would like to know how can i make a random respawn in the “basepale” for the zombie model

image

Script:

local NPC = game.ReplicatedStorage.Zombie
local spawner = script.Parent

	while true do
		local Clone = NPC: Clone(5)
		Clone.Parent = workspace
		Clone.Torso.CFrame = spawner.CFrame
		wait(3)
	end

Could someone help me with this code, please… :frowning:

Use SetPrimaryPartCFrame instead of setting torso’s CFrame.

Try this.

local NPC = game.ReplicatedStorage.Zombie
local spawner = script.Parent
while true do
local Clone = NPC:Clone(5)
Clone.Parent = workspace
Clone:SetPrimaryPartCFrame(spawner.CFrame)
wait(3)
end

Make sure zombie model has a primary part.

how do i know if that model has a primary part? :scream:

image

You mean you want it to spawn in a random location right??

local NPC = game.ReplicatedStorage.Zombie
local spawner = script.Parent

local centerposition = Vector3.new(0,5,0) --center of your map
local xSize = 30 --how big map is on X axis
local zSize = 30 -- how big your map is on Y axis

	while true do
		local Clone = NPC: Clone(5)
		Clone.Parent = workspace
                local randomX, randomZ = math.random(-xSize/2,xSize/2), math.random(-zSize/2,zSize/2)
		Clone.Torso.CFrame = CFrame.new(centerposition + Vector3.new(randomX, 0, randomZ
		wait(3)
	end
2 Likes

Click on model and go to the properties.

If model doesn’t have a primary part, select HumanoidRootPart as primary part.

the problem is that only 2 spawn and they don’t appear anymore … I need to make 1 appear every 1 second

image

it happens exactly the same as with my code :frowning: I press play and they always appear next to me, I need to make 1 zombie appear every 1 second and make it random in the basepale :frowning:

code

local NPC = game.ReplicatedStorage.Zombie

local spawner = script.Parent

local centerposition = Vector3.new(0,5,0) --center of your map

local xSize = 30 --how big map is on X axis

local zSize = 30 -- how big your map is on Y axis

while true do

local Clone = NPC: Clone(5)

Clone.Parent = workspace

local randomX, randomZ = math.random(-xSize/2,xSize/2), math.random(-zSize/2,zSize/2)

Clone.Torso.CFrame = CFrame.new(centerposition + Vector3.new(randomX, 0, randomZ))

wait(3)

end

the problem is that only 2 spawn and they don’t appear anymore … I need to make 1 appear every 1 second

Then, try this.

local NPC = game.ReplicatedStorage.Zombie
local spawner = script.Parent
while true do
wait(1)
local Clone = NPC:Clone()
Clone.Parent = workspace
Clone:SetPrimaryPartCFrame(spawner.CFrame)
end

Probably moving the torso doesn’t do anything, maybe you need to use :SetPrimaryPartCFrame. I gotta go, good luck, I can help you later.

still appearing only 2 :frowning:

image

Do you have any other script that affects this ?

i already did it… its okay no problem ty :smiley:

no one more i delete those two scripts inside zombie model and still appearing only 2 :c

image

Try creating a script in ServerScriptService, and type this.

local NPC = game.ReplicatedStorage.Zombie
local spawner = game.Workspace:FindFirstChild(“Spawner”)
while true do
wait(1)
local Clone = NPC:Clone()
Clone.Parent = workspace
Clone:SetPrimaryPartCFrame(spawner.CFrame)
end

Delete that script in part.

still appearing only 2 :frowning:

image

image

Any errors in output ?

I tried this in a place and it worked.

got this D:

image

I think you inserted wrong script or messed it up. There is nothing related to torso in script.

local NPC = game.ReplicatedStorage.Zombie
local spawner = game.Workspace:FindFirstChild(“Spawner”)
while true do
wait(1)
local Clone = NPC:Clone()
Clone.Parent = workspace
Clone:SetPrimaryPartCFrame(spawner.CFrame)
end

Copy and paste it to server script.

And click to the error in output and see where it takes you to.

It was an error of the scripts that the zombie had, I just eliminated the zombie scripts and the output does not give me any error but only 2 zombies continue to appear

image

I dont want to belive its this but, anchor the spawner (part), then try it.

It might be part is falling of map and getting destroyed because not anchored.

1 Like