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

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

Asked by 7 years ago

This is my current script

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

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

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 ;)

0
Instead of doing while true do wait(), you can do while wait() do. It looks cleaner. xForVowels 6 — 5y
Ad
Log in to vote
1
Answered by
phxtn 154
7 years ago
Edited 7 years ago
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.

0
I'm pretty sure you have to use the :MakeJoints() method if you are disjointing them.... KingLoneCat 2642 — 7y
1
lol, I didn't know about 'while true do' the time i asked this question PhoenixVortex_RBLX 33 — 6y

Answer this question