Hello so I need a script that when you click a block a zombie npc spawns.
I have tried to get tutorials on how to do it but I cant find any and I have tried to mod roblox’s zombie spawner so if anyone can I help me then many thanks.
an npc that attacks or just stand still?
put an npc in rep storage
Add a part, parent a click detector and a script to it
write in script:
local zombie = game.ReplicatedStorage["INSERT NPC NAME HERE"]
zombie.Parent = workspace
zombie.HumanoidRootPart.CFrame = script.Parent.CFrame
end)
also put
script.Parent.ClickDetector.MouseClick:Connect(function()
in front of it
If you want it to loop forever:
task.spawn(function()
while true do
local zombieClone = game.ReplicatedStorage.Zombie:Clone()
zombieClone.Parent = workspace
task.wait(5)
end
end)
If you want it to repeat 50 times:
for i = 1,50 do
local zombieClone = game.ReplicatedStorage.Zombie:Clone()
zombieClone.Parent = workspace
task.wait(5)
end
I need it to kill People to.
So when they click it it spawns a amount.
Get a zombie out of the Toolbox and just use their scripts.
It works thanks but I need it to spawn at a different position and not on the button so how would that be done.
When you Clone the zombie from rep Storage just set the CFrame of the Humanoid Root Part of the zombie to a desired position in the workspace. HumanoidRootPart.CFrame = CFrame.new(Position you want it.)
Thanks it works but when I click the block again it doesn’t spawn a new zombie I don’t know for sure but do I need a clone part in the script and if so can you show me what it needs to look like.
Edit: I found a fix for it so just do this:
script.Parent.ClickDetector.MouseClick:Connect(function()
local zombie = game.ReplicatedStorage["Zombie"]:Clone()
zombie.Parent = workspace
zombie.HumanoidRootPart.CFrame = script.Parent.CFrame
end)
script.Parent.ClickDetector.MouseClick:Connect(function()
local zombie = game.ReplicatedStorage["Zombie"]:Clone()
zombie.Parent = workspace
zombie.HumanoidRootPart.CFrame = Vector3.new(0, 0, 0)
end)
Set the Vector3.new(0, 0, 0) to whatever coords you want it to spawn at if you want it specific
An easier solution would be to place parts all around the Workspace
and set the CFrame of the zombie’s HRP to the Part’s CFrame
Same difference, going to get the same outcome