#script isnt respawning model

1 messages · Page 1 of 1 (latest)

unreal field
#

local zombie = script.Parent
local originalPosition = zombie:GetPivot()

local function respawnZombie()
task.wait(2) -- Wait for 2 seconds before respawning
local newZombie = zombie:Clone()
newZombie.Parent = game.Workspace -- Ensure the new zombie is parented to the workspace
newZombie:PivotTo(originalPosition)

-- Reset visibility and other properties
for _, part in newZombie:GetDescendants() do
    if part:IsA("BasePart") then
        part.Transparency = 0  -- Ensure the zombie is visible
        local originalMaterial = part:GetAttribute("OriginalMaterial")
        local originalColor = part:GetAttribute("OriginalColor")
        if originalMaterial then
            part.Material = Enum.Material[originalMaterial]  -- Convert string to Enum
        end
        if originalColor then
            part.Color = Color3.fromRGB(originalColor.R, originalColor.G, originalColor.B)  -- Convert table to Color3
        end
    end
end

-- Connect the respawn function to the new zombie's Humanoid
local newHumanoid = newZombie:FindFirstChildOfClass("Humanoid")
if newHumanoid then
    newHumanoid.Died:Connect(respawnZombie)
end

-- Ensure the new zombie is initialized before destroying the original
if newZombie.Parent == game.Workspace then
    zombie:Destroy()
end

end

-- Store original properties
for _, part in zombie:GetDescendants() do
if part:IsA("BasePart") then
part:SetAttribute("OriginalMaterial", tostring(part.Material)) -- Store as string
part:SetAttribute("OriginalColor", {R = part.Color.R * 255, G = part.Color.G * 255, B = part.Color.B * 255}) -- Store as table
end
end

local humanoid = zombie:FindFirstChildOfClass("Humanoid")
if humanoid then
humanoid.Died:Connect(respawnZombie)
end

unreal field
fallow meteorBOT
#

studio** You are now Level 2! **studio