[Help] Ragdoll toggle

roleplay
help
script
scripting
ragdoll

#1

So I’m trying to call a bunch of scripts form a menu. i got quite a few working liek animations, then only one I’m struglign on is a toggle Ragdoll feature.

Here is what I wrote


local noragdoll = true

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

The whole menu just breaks when i use this. Any ideas?


#2

No condition to end this loop. Literally runs forever (well, until the game stops).

I believe you mean Wait (you’re probably going to get an error that “wait” doesn’t exist).

Could just use PlayerPedId() returns the same result and, looks nicer.


#3

Yeah I got the loop to run, I just wouldn’t break it. i want it so if the Event is called again, the loop breaks. I just cannot find out how