Player cant reset with ragdoll PlatformStand

I made a time ragdoll using PlatformStand and player cant reset until the ragdoll ends

when the player reset character it need wait the ragdoll end to die

code
SERVER:
local Character: Model = script.Parent
local Player : Player = game:GetService(“Players”):GetPlayerFromCharacter(Character)
local HRP: BasePart = Character:WaitForChild(“HumanoidRootPart”)
local Torso: BasePart = Character:WaitForChild(“Torso”)
local Humanoid: Humanoid = Character:FindFirstChildOfClass(“Humanoid”)

if Player then
Character.Humanoid.BreakJointsOnDeath = false
Character.Humanoid.RequiresNeck = false

local attachmentCFrames = {

["Neck"] = {CFrame.new(0, 1, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1), CFrame.new(0, -0.5, 0, 0, -1, 0, 1, 0, -0, 0, 0, 1)},
["Left Shoulder"] = {CFrame.new(-1.3, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1), CFrame.new(0.2, 0.75, 0, -1, 0, 0, 0, -1, 0, 0, 0, 1)},
["Right Shoulder"] = {CFrame.new(1.3, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1), CFrame.new(-0.2, 0.75, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1)},
["Left Hip"] = {CFrame.new(-0.5, -1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},
["Right Hip"] = {CFrame.new(0.5, -1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1), CFrame.new(0, 1, 0, 0, 1, -0, -1, 0, 0, 0, 0, 1)},

}

local ragdollInstanceNames = {

["RagdollAttachment"] = true,
["RagdollConstraint"] = true,
["ColliderPart"] = true,

}

local RagdollValue = Character:WaitForChild(“Ragdolled”)

local function createColliderPart(part: BasePart)

if not part  then return end

local rp = Instance.new("Part")
rp.Name = "ColliderPart"
rp.Size = part.Size/1.7
rp.Massless = true			
rp.CFrame = part.CFrame
rp.Transparency = 1

local cw = Instance.new("Weld")
cw.Name = "ColliderWeld"
cw.Part0 = rp
cw.Part1 = part
cw.Parent = rp
rp.Parent = Character

end

local function replaceJoints()
Character.Health.Enabled = false
Humanoid.AutoRotate = false
Humanoid.PlatformStand = true

local AntiLagWeld = Instance.new("Weld")
AntiLagWeld.Name = "AntiLagWeld"
AntiLagWeld.Part0 = HRP
AntiLagWeld.Part1 = Torso
AntiLagWeld.Parent = HRP
task.spawn(function()
	Humanoid.EvaluateStateMachine = false
	wait(0.5)
	Humanoid.EvaluateStateMachine = true
end)
task.spawn(function()

	for _, motor in pairs(Character:GetDescendants()) do

		if motor:IsA("Motor6D") then

			motor.Part0.Massless = true
			motor.Part1.Massless = true

		end

	end
	
	
	
	if Humanoid.Health ~= 0 then
 	task.wait(0.5)
		
		for _, motor in pairs(Character:GetDescendants()) do

			if motor:IsA("Motor6D") then

				motor.Part0.Massless = false
				motor.Part1.Massless = false

			end

		end
		
	end	

end)

for _, motor in pairs(Character:GetDescendants()) do
	
	if motor:IsA("Motor6D") then
								
		local a0, a1 = Instance.new("Attachment",Character.Torso), Instance.new("Attachment",Character.Torso)
		
		a0.CFrame = attachmentCFrames[motor.Name][1]
		
		a1.CFrame = attachmentCFrames[motor.Name][2]

		a0.Name = "RagdollAttachment"
		a1.Name = "RagdollAttachment"

		createColliderPart(motor.Part1)

		local b = Instance.new("BallSocketConstraint")
		b.Attachment0 = a0
		b.Attachment1 = a1
		b.LimitsEnabled = true
		b.TwistLimitsEnabled = true
		b.Name = "RagdollConstraint"
		
		a0.Parent = motor.Part0
		a1.Parent = motor.Part1
		b.Parent = motor.Parent
			
		motor.Enabled = false
		
	end
	
end

end

local function resetJoints()

Character.Health.Enabled = true
if HRP:FindFirstChild("AntiLagWeld") then
HRP:FindFirstChild("AntiLagWeld"):Destroy()
end
for _, instance in pairs(Character:GetDescendants()) do

	if ragdollInstanceNames[instance.Name] then

		instance:Destroy()

	end

	if instance:IsA("Motor6D") then

		instance.Enabled = true

	end
end


Humanoid.AutoRotate = true
Humanoid.PlatformStand = false

local CheckRayRestrictions = RaycastParams.new()
CheckRayRestrictions.FilterDescendantsInstances = {Character}
CheckRayRestrictions.FilterType = Enum.RaycastFilterType.Exclude
CheckRayRestrictions.IgnoreWater = false

local CheckRay = game.Workspace:Raycast(HRP.Position, Vector3.new(0, -5, 0), CheckRayRestrictions)
	
local GetUpHeight = 0

if CheckRay then
	
	GetUpHeight = 3.5
	
end

local NewOrigo = Instance.new("Part")
NewOrigo.Position = HRP.Position + Vector3.new(0, GetUpHeight, 0)	
Character:PivotTo(NewOrigo.CFrame)
game.Debris:AddItem(NewOrigo, 0)

end

local function Ragdoll(value: boolean)

pcall(function()

	if value then
		Character.Torso.CanCollide =false
		Character.Head.CanCollide =false
		replaceJoints() 
		
	else 
		Character.Torso.CanCollide =true
		Character.Head.CanCollide =true
		resetJoints() 
		
	end
	
end)	

end

RagdollValue.Changed:Connect(Ragdoll)

	end

CLIENT:
local Character: Model = script.Parent
local HumanoidRootPart: BasePart = Character:WaitForChild(“HumanoidRootPart”)
local Humanoid: Humanoid = Character:WaitForChild(“Humanoid”)
local RagdollValue: BoolValue = Character:WaitForChild(“Ragdolled”)

local function push()

HumanoidRootPart:ApplyImpulse(-HumanoidRootPart.CFrame.LookVector.Unit * 100)

end
RagdollValue:GetPropertyChangedSignal(“Value”):Connect(function()

if (Humanoid.Health == 0) then
	
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	
	if Humanoid.FloorMaterial ~= Enum.Material.Air  and Humanoid.FloorMaterial ~= Enum.Material.Water then
	
		push()
		
	end	
	
	return
		
end

if RagdollValue.Value then
	
	Character.Health.Enabled = false

	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
	Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Landed,false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying,false)

	Humanoid.PlatformStand = true
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead,true)
elseif not RagdollValue.Value then
	Character.Health.Enabled = true
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
	Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, true)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Landed,true)
	Humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying,true)
	Humanoid.PlatformStand = false

end

end)

Humanoid.Died:Connect(push)

video:

i tried to make player dead state true but it not working after this i tryed to make player state ragdoll and in sequence psychical but nothing working