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

Trouble with cloning a part back into player when they respawn?

Asked by 3 years ago
Edited 3 years ago

I have a character select gui which welds a part to the player when they select their desired character.(which isn't important) but... I want to make it so that part is cloned into the workspace while the player's descendants have cleared after they have died, and while the part is placed in the workspace, i want it to be welded back into/onto the player. My problem is that the part is welding into the players dead body and not onto the players respawned body, and is frozen in the workspace, Any help?

local Char = script.Parent
local Hum = Char.Humanoid
Char.Humanoid.BreakJointsOnDeath = false
Char.Humanoid.RequiresNeck = false
Char.Archivable = true

Hum.Died:Connect(function(player)
    local CharClone = Char:WaitForChild("Part"):Clone()
    CharClone.Parent = workspace
    CharClone.Anchored = true
wait(4)
    CharClone.Parent = player.Character or player.CharacterAdded:Wait()
    CharClone.CFrame = CFrame.new(player.Character.Torso.Position)
    CharClone.Anchored = false

    local Y = Instance.new("Weld")
    Y.Part0 = player.Character.Torso
    Y.Part1 = CharClone
    Y.Parent = Y.Part0
end)

Answer this question