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

NPC Characters not spawning correctly?

Asked by 8 years ago
Edited 8 years ago

I am creating an RPG (RolePlayGame) and have run into a problem.

npc = script.Parent:Clone()

function Died()
    wait(5)
    npc.Parent = script.Parent.Parent
    npc:MakeJoints()
    npc.Enemy.Health = npc.Enemy.MaxHealth
    script.Parent:Remove()
end

script.Parent.Enemy.Died:connect(Died)


Sometimes the npc will respawn, sometimes it won't ever respawn again. I get this error message.

16:44:35.337 - Workspace.Weak Bandit..Respawn:5: attempt to index global 'npc3' (a nil value)
16:44:35.339 - Stack Begin
16:44:35.341 - Script 'Workspace.Weak Bandit..Respawn', Line 5
16:44:35.343 - Stack End

Anyone know what is wrong?

1 answer

Log in to vote
0
Answered by
FiredDusk 1466 Moderation Voter
8 years ago

Make sure to add a humanoid in the Enemy. The Died event only works in the humanoid.

npc = script.Parent:Clone()

function Died()
    wait(5)
    npc.Parent = script.Parent.Parent
    npc:MakeJoints()
    npc.Enemy.Health = npc.Enemy.MaxHealth
    script.Parent:Remove()
end

script.Parent.Enemy.Humanoid.Died:connect(Died) --Here is where I added 'Humanoid'


Ad

Answer this question