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

how to make an npc spawner?

Asked by 4 years ago
Edited 4 years ago

ok so i got the spawner it is just that i only want it to spawn the npc when the previous one has died this is my current script so far:

1local guards = game.ReplicatedStorage.Guards
2 
3for _,i in pairs(guards:GetChildren()) do
4    local clone = i:Clone()
5    clone.Parent = workspace.Guards
6    clone.Humanoid.Died:Connect(function()
7    end)
8end

game.ReplicatedStorage.Guards is a folder that contains a lot of guards or at least is going to rn it only has one so right now i don't even think this will work because once the loop has finished im not sure if it will even run when it dies and second im not sure what to put when the thing has died because i would put local clone = bla bla bla then i would put clone.hum.died:connec and in that i would have to put that in and do that forever and ever so is there any way to fix those two problems? i was thinking i could fire a remote event but i would need to fire it back agian in a client cause there both in server anyway is there any way to fix this?

1 answer

Log in to vote
1
Answered by 4 years ago

Why didn't you write a recursive function for respawn?

01local guards = game.ReplicatedStorage.Guards
02 
03function recursiveSpawn(i)
04    local clone = i:Clone()
05    clone.Parent = workspace.Guards
06    clone.Humanoid.Died:Connect(function()
07        recursiveSpawn(i)
08    end)   
09end
10 
11for _,i in pairs(guards:GetChildren()) do
12    recursiveSpawn(i)
13end
0
ohh i was thinking of doing that but when i did it, it didn't auto fill it for me and i assumed that you can't call a function in the same function botw_legend 502 — 4y
Ad

Answer this question