I’m trying to clone the character model so when the player respawns, they can see where they last died. Whenever I try to use :Clone(), it returns nil instead of giving me a copy I can iterate over to delete attachments and local scripts from.
Is this a bug on my end, or is it a feature that will require me to manually clone the contents to a new model?
local function createDeadCopy(rig)
local clone = rig:Clone()
for _, instance in clone:GetDescendants() do
if instance:IsA("Attachment") or instance:IsA("LocalScript") then
instance:Destroy()
end
end
return clone
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
humanoid.BreakJointsOnDeath = false
--Placing a dead copy of player
humanoid.Died:Connect(function()
local deadChar = createDeadCopy(char)
deadChar:PivotTo(char.WorldPivot)
char:Destroy()
deadChar.Parent = workspace
end)
end)
end)