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

Respawn script for my enemy npcs doesn't work as I would like it to?

Asked by 8 years ago

So, I have an enemy setup wherei t moves back and forth, and if you jump on it's head, it dies. I have a respawn script so after 5 seconds of it being dead, it respawns, however, when it respawns the scripts I have set for it fail, for example, when I jump on its head it doesn't die, and it doesn't move back and forth like it used too.

01-- Respawn Script (Outside of NPC Model)
02local clone = workspace.Goomba:Clone()
03 
04workspace.Goomba.Humanoid.Died:connect(function()
05wait(5)
06workspace.Goomba:Destroy()
07clone.Parent = workspace
08local clone = workspace.Goomba:Clone()
09 
10 
11end)
1--Jump on head = die script (inside model)
2function OnTouched()
3    local h = game.Workspace.Goomba:findFirstChild("Humanoid")
4    if h ~= nil then
5        h.Health = 0
6    end
7end
8 
9script.Parent.Touched:connect(OnTouched)
1--walk script for npc (outside of its model)
2while true do
3script.Parent.Goomba.Humanoid:MoveTo(Vector3.new(0.776, -0, -20.173))
4wait(4)
5script.Parent.Goomba.Humanoid:MoveTo(Vector3.new(0.776, -0, -33.173))
6wait(4)
7end

This is kinda urgent! Any help appreciated

Answer this question