[Help] Ragdoll script

So I’m making a ragdoll script that I’ll call from a menu, i got other scripts to work like roll windows, animations ect, but I cant get the ragdoll to work, if I just at the ragdoll line, the players falls on the ground and just gets back up. I want it to be a toggle feature

here it is.

--[[ RAGDOLL SCRIPT ]]--
local noragdoll = true
AddEventHandler('Ragdoll', function()
	local player = GetPlayerPed( -1 )
	if ( DoesEntityExist( player ) and not IsEntityDead( player )) then
		if ( noragdoll ) then
			noragdoll = false
		else
			noragdoll = true
		end
	end
	while ( noragdoll = false ) do
		SetPedToRagdoll(GetPlayerPed(-1), 1000, 1000, 0, 0, 0, 0)
	end
end)

if I do

local noragdoll = true
AddEventHandler('Ragdoll', function()
	local player = GetPlayerPed( -1 )
	if ( DoesEntityExist( player ) and not IsEntityDead( player )) then
		if ( noragdoll ) then
			noragdoll = false
		else
			--while ( noragdoll = false ) do
			SetPedToRagdoll(GetPlayerPed(-1), 1000, 1000, 0, 0, 0, 0)
			--end
			noragdoll = true
		end
	end
end)

I get this result.
This is a gif btw, refresh if it isnt playing

any ideas?

Because you only set ragdoll time to 1000ms read the docs.