Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

how to make an npc spawner?

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

✓ Accepted answer

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

1 comment

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

This discussion is preserved as it was. New answers, comments, and votes are closed.