0

# How to script an entity spawner?

LazokkYT 113
1 month ago
Edited 1 month ago

Hi I want to make a mob spawner similar to Islands'. I'm just asking if anyone has any ideas on how to achieve this? I want to make a spawner that spawns in a mob when the already spawned in mob is killed. If you want an example, you can look at Islands' slime spawner system. I don't really want code, just an idea of how it would work.

Thanks!

1

Hello,

If the script above by "imnotaguest1121" did not work then try out my idea!

Connect Function When NPC Dies

Make a spawner anywhere in the map wherever you want and make the Zombie NPC and parent it to ReplicatedStorage. Make a script in the Zombie that connects a function() to an Humanoid.Died Event when zombie dies, you can obtain that by:

Humanoid.Died:Connect(function()
-- script here
end)


When the humanoid dies what you can do is Clone() the Zombie from ReplicatedStorage and set the position of the zombie to the spawner's Position. After about 2 - 5 seconds after the Zombie death you can :Destroy the Zombie.

Specific Amount Of NPC's

If you want a specific amount of Zombies, lets say about 5 then you can put the new cloned NPC's in a NPC folder and then count the children and add one if there is not enough Zombies, this will be obtained by:

-- References --
local NPCFolder = game.Workspace.NPCFolder
local NPC = game.ReplicatedStorage.Zombie
local MaxZombies = 5

-- functions --
while wait(0.5) do
if #NPCFolder:GetChildren() < ( MaxZombies + 1 ) then -- Counts Zombies
local NewNPC = NPC:Clone() -- Clones Zombie
NewNPC.Parent = game.Workspace.NPCFolder -- Parents Zombie to folder
NewNPC.Position = Spawner.Position + Vector3.new(0,4,0) -- Sets Position
end
end


Spawn a NPC after the Old NPC's Death

if you want one or more Zombies but they spawn after the Zombies in Workspace die what you can do is:

-- Variables --
local Humanoid = script.Parent:FindFirstChild("Humanoid")
local NPC = game.ReplicatedStorage.Zombie
local Spawner = game.Workspace.Spawner

-- functions --
Humanoid.Died:Connect(function() -- connect function when Zombie dies
local NewNPC = NPC:Clone() -- Clones NPC
NewNPC.Parent = game.Workspace -- Parents NPC to Workspace
NewNPC.Position = Spawner.Position + Vector3.new(0,4,0) -- Sets position
wait(3)
script.Parent:Destroy -- Destroys previous Zombie
end)


More On Humanoid.Died

I hope this Helps!

0
Omg tysm! I never thought of using humanoid.died! LazokkYT 113 — 29d
0
your welcome, I am very Impressed from how fast you replied!, this is my first answer so i am thankful that it helped! Hi_People1133 168 — 29d
1
Edited 1 month ago

Oh sorry! I didn't read that, anyway here Is a simple script:

local NPC = game.ReplicatedStorage. --ObjectNameHere
local spawner = script.Parent

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

0
Uhm, excuse me did you read what I said? I specifically said "I don't really want code". I'm literally just looking for ideas on how to make this work. LazokkYT 113 — 1mo
0
Oh sorry imnotaguest1121 89 — 1mo
0
It's okay, but I actually already have that in my game. It's just that I'm looking for a way to detect when the NPC is dead. LazokkYT 113 — 29d