Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to script an entity spawner?

Asked by
LazokkYT 117
2 years ago
Edited 2 years 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!

2 answers

Log in to vote
1
Answered by 2 years ago

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:

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

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:

01-- References --
02local NPCFolder = game.Workspace.NPCFolder
03local NPC = game.ReplicatedStorage.Zombie
04local MaxZombies = 5
05 
06-- functions --
07while wait(0.5) do
08    if #NPCFolder:GetChildren() < ( MaxZombies + 1 ) then -- Counts Zombies
09        local NewNPC = NPC:Clone() -- Clones Zombie
10            NewNPC.Parent = game.Workspace.NPCFolder -- Parents Zombie to folder
11        NewNPC.Position = Spawner.Position + Vector3.new(0,4,0) -- Sets Position
12    end
13end

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:

01-- Variables --
02local Humanoid = script.Parent:FindFirstChild("Humanoid")
03local NPC = game.ReplicatedStorage.Zombie
04local Spawner = game.Workspace.Spawner
05 
06-- functions --
07Humanoid.Died:Connect(function() -- connect function when Zombie dies
08    local NewNPC = NPC:Clone() -- Clones NPC
09    NewNPC.Parent = game.Workspace -- Parents NPC to Workspace
10    NewNPC.Position = Spawner.Position + Vector3.new(0,4,0) -- Sets position
11    wait(3)
12    script.Parent:Destroy -- Destroys previous Zombie
13end)

More On Humanoid.Died

I hope this Helps!

0
Omg tysm! I never thought of using humanoid.died! LazokkYT 117 — 2y
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 218 — 2y
Ad
Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

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

1local NPC = game.ReplicatedStorage. --ObjectNameHere
2local spawner = script.Parent
3 
4while true do
5  local Clone = NPC: Clone()
6 Clone.Parent = workspace
7 Clone.Torso.CFrame = spawner.CFrame
8 wait(3)
9end
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 117 — 2y
0
Oh sorry imnotaguest1121 362 — 2y
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 117 — 2y

Answer this question