#Creating Mob Spawner

10 messages · Page 1 of 1 (latest)

trail sparrow
#

I am learning and trying to make my own mob spawner where that mob is going to spawn after it dies but...

#

for some reason, the npc can only spawn once, after that it'll no longer spawns

#

Code:

#

More details:

#

Killed once

#

Sometimes when it resurrects, it looks like this... sometimes its normal

#

Killed twice and is no longer respawning...

trail sparrow
#

Ok so i solved the issue myself...

        if spawner then
            local newNPC = npc:Clone()
            local originalPosition = npc.PrimaryPart and npc.PrimaryPart.Position or Vector3.new(0, 0, 0)
            wait(respawnTime)
            npc:Destroy()
            print"Destroying NPC..."
            wait(3)
            local humanoid = newNPC:FindFirstChildOfClass("Humanoid")
            if humanoid then
                humanoid.Died:Connect(function()
                    respawnNPC(npcType, newNPC)
                end)
            end
            humanoid.Health = humanoid.MaxHealth
            newNPC.Parent = workspace.MobNPC[npcType]
            newNPC:MakeJoints()
            newNPC:SetPrimaryPartCFrame(CFrame.new(originalPosition))
            print"Respawned NPC..."
        else warn("Spawn point not found for NPC:", npcType)
        end