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

How do you make NPCs respawn? My current script doesn't work

This is my current script

if script.Parent.Humanoid.Health = 0 then
wait(3)
script.Parent.Humanoid.Health = 100 -- The max health

2 answers

✓ Accepted answer

Well, one way is to name every NPC differently so you might name it "Bob" or "Joe" if you have 2 NPC's with the same name then this won't work.

Have these steps:

Make sure you have 2 of the NPC

Have 1 in WorkSpace

Have 1 in ReplicatedStorage

Make sure you know where you want the NPC to spawn

Put this script in serverScriptService

local spawnLocation = game.Workspace:WaitForChild("NPCSpawn") --Where you want the NPC to spawn

while true do
	wait()
	if not game.Workspace.FindFirstChild("NPCNAME") then--Npc name here 
		local CloneNpc = game.ReplicatedStorage:WaitForChild("NPCName"):Clone()
		CloneNpc.Parent = game.Workspace
		CloneNpc.Position = Vector3.new(spawnLocation.Postion)
	end
end

Make sure you name everything correctly if there is any errors or comment, comment on this answer. Otherwise, if it worked please accept answer ;)

1 comment

0

Instead of doing while true do wait(), you can do while wait() do. It looks cleaner.

DaHealth = 100 -- Change this to full health
DeHealth = 0
Hum = script.Parent.Humanoid.Health
Photon = true -- Hehe :)

while Photon == true then 
if Hum == DeHealth then -- If the health is 0
wait(3)
Hum = DaHealth -- The Health will go to Full Health.
end)

I don't know if it will work.

2 comments

0

I'm pretty sure you have to use the :MakeJoints() method if you are disjointing them....

1

lol, I didn't know about 'while true do' the time i asked this question

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