code:
local NPC = game.ReplicatedStorage.zombie
local Spawner = script.Parent
while true do
local Clone = NPC: Clone()
Clone.HumanoidRootPart.CFrame = CFrame.new(0.917, 0.5, -0.727)
Clone.Parent = workspace
wait(5)
end
anything i miss did?
code:
local NPC = game.ReplicatedStorage.zombie
local Spawner = script.Parent
while true do
local Clone = NPC: Clone()
Clone.HumanoidRootPart.CFrame = CFrame.new(0.917, 0.5, -0.727)
Clone.Parent = workspace
wait(5)
end
anything i miss did?
You’re setting the CFrame of the zombie model to the same thing every time. You could consider setting it to the CFrame value of other parts or using something such as math.random() to spawn it in different places.
You’re just only setting 1 CFrame, and not multiple CFrame values each time
You could probably just do something relevant to math.random() to spawn it in different locations
now it isn’t even spawning them in.
Well you’d have to actually pass values inside math.random(), and do it for all the appropriate values you want to make random on the CFrame. The link I provided simply shows some documentation for the math library, where you can find a description of math.random(). You’ll have to figure out the values you want to make random or alternatively, simply set the zombie model’s PrimaryPart CFrame to the CFrame of another part in the game.
As the first two people said, you need to use math.random()
here’s a simple code that I wrote before that might help you:
local players = game:GetService(“Players”)
local spawns = game.Workspace.spawns:GetChildren()
local randomspawn = spawns[math.random(5,#spawns)]
script.Parent.Touched:Connect(function(Hit)
if Hit and Hit.Parent and Hit.Parent:FindFirstChild(“Humanoid”) then
Hit.Parent:FindFirstChild(“HumanoidRootPart”).CFrame = randomspawn.CFrame
end
end)
hope this helped!
i think it is better for me to just make spawns that spawns zombie at one place. i cant understand coding.
Might i say to use this series he’s very good at teaching code.
I mean it is possible, & yeah I can understand from your standpoint that coding can be confusing for ya but it really takes practice more or less so how about we try this instead?
local NPC = game.ReplicatedStorage.zombie
local Spawners = #workspace.Spawners:GetChildren()
while true do
local RandomSpawner = Spawners[math.random(1, Spawners)]
local Clone = NPC:Clone()
Clone.Parent = workspace
Clone:MakeJoints()
Clone.HumanoidRootPart.Position = RandomSpawner.Position
wait(5)
end
So, let’s break this down here that you can hopefully understand!
local NPC = game.ReplicatedStorage.zombie
local Spawners = #workspace.Spawners:GetChildren() --Spawners will actually be a folder, from where we can put all our Zombie Spawns in
So, the first thing we’re doing here is getting the Zombie in our ReplicatedStorage (Pretty simple)
The local Spawners variable is actually getting the number of all the Spawners in that specific folder, so if we were to put:
Alright, next:
while true do
local RandomSpawner = Spawners[math.random(1, Spawners)]
local Clone = NPC:Clone()
Clone.Parent = workspace
Clone:MakeJoints()
Clone.HumanoidRootPart.Position = RandomSpawner.Position
wait(5)
end
This shouldn’t be too difficult to explain hopefully, (I would personally change the while true do to while wait(5) do but whatever)
Now the first thing we’re defining in our loop is actually getting a random spawn from within our local Spawners variable, and since (I believe) getting the Children with # will result being in a table, which is basically a set of data (Here is a example down below):
local RandomSpawner = Spawners[math.random(1, Spawners)]
print(RandomSpawner.Name)
--Result should be the name of the RandomSpawner, or let's say Spawn2
--Running it again will randomize, from a range of between 1 & 5
After we get our RandomSpawner, we can go ahead and Clone our NPC like so:
local Clone = NPC:Clone()
Clone:MakeJoints()
Clone.HumanoidRootPart.Position = RandomSpawner.Position
Clone.Parent = workspace
We first Clone it, and then create the Joints for it (Since it’s a Model, Joints needs to be made so that they don’t break apart as shown in this GIF except you don’t reset lol, it happens automatically):

Next, we change the position from where the Clone will actually spawn at with the RandomSpawner’s Position (Which should be just a regular part hopefully)
Then afterwards, we Parent our Clone into the workspace, then it waits 5 seconds to do that loop yet again!
(Hope I explained it well, if you have any more questions feel free to ask!
)