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:

local guards = game.ReplicatedStorage.Guards

for _,i in pairs(guards:GetChildren()) do
    local clone = i:Clone()
    clone.Parent = workspace.Guards
    clone.Humanoid.Died:Connect(function()
    end)
end

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?

local guards = game.ReplicatedStorage.Guards

function recursiveSpawn(i)
    local clone = i:Clone()
    clone.Parent = workspace.Guards
    clone.Humanoid.Died:Connect(function()
        recursiveSpawn(i)
    end)    
end

for _,i in pairs(guards:GetChildren()) do
    recursiveSpawn(i)
end
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