Ragdoll Modular Script isn't ending a ragdoll because it stops at a task.wait

  1. I have a ragdoll script that launches the player after touching a part

  2. The player does not get unragdolled after the amount of time, it never goes beyond the second task.wait

  3. I have tried using a coroutine, still has the same problem of the second task.wait() not passing through. I also have tried commenting out the Torso velocity, removing direction and strength variables, and doing both and it still doesn’t work

local ragdoll = {}

function ragdoll.doRagdoll(ragTime) -- This is the one that works
	if (notRagdolled) then
		notRagdolled = false
		for _, motor6d in ipairs(script.Parent:GetDescendants()) do
			if motor6d:IsA("Motor6D") then
				motor6d.Enabled = false
			end
		end

		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

		headBodyJoint.Enabled = true
		leftABodyJoint.Enabled = true
		rightABodyJoint.Enabled = true
		leftLBodyJoint.Enabled = true
		rightLBodyJoint.Enabled = true
		
		script.Parent.HumanoidRootPart.Anchored = true
		
		print("Start2")
		task.wait(1)
		print("Can do 1")
		task.wait(ragTime)
		notRagdolled = true
		script.Parent:FindFirstChild("Torso"):SetNetworkOwner(player)
		print("End")
		script.Parent.HumanoidRootPart:PivotTo(script.Parent.Torso.CFrame)

		script.Parent.HumanoidRootPart.Position = Vector3.new(script.Parent.HumanoidRootPart.Position.X,script.Parent.HumanoidRootPart.Position.Y +0.5,script.Parent.HumanoidRootPart.Position.Z)

		script.Parent.HumanoidRootPart.Anchored = false

		script.Parent.HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero

		script.Parent.HumanoidRootPart:SetNetworkOwner(nil)

		script.Parent.HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero

		script.Parent.HumanoidRootPart:SetNetworkOwner(player)

		for _, motor6d in ipairs(script.Parent:GetDescendants()) do
			if motor6d:IsA("Motor6D") then
				motor6d.Enabled = true
			end
		end

		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)

		headBodyJoint.Enabled = false
		leftABodyJoint.Enabled = false
		rightABodyJoint.Enabled = false
		leftLBodyJoint.Enabled = false
		rightLBodyJoint.Enabled = false
		
		
	end

end

function ragdoll.launch(ragTime,direction, strength) -- This is the one that doesn't work
	print(ragTime)
	if (notRagdolled) then
		
		notRagdolled = false
		for _, motor6d in ipairs(script.Parent:GetDescendants()) do
			if motor6d:IsA("Motor6D") then
				motor6d.Enabled = false
			end
		end

		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)

		headBodyJoint.Enabled = true
		leftABodyJoint.Enabled = true
		rightABodyJoint.Enabled = true
		leftLBodyJoint.Enabled = true
		rightLBodyJoint.Enabled = true

		script.Parent.HumanoidRootPart.Anchored = true

		task.wait()
		waitTime = ragTime
		
		local torso = script.Parent:FindFirstChild("Torso")
		if torso:IsA("Part") then
			torso:SetNetworkOwner(nil)
			torso.AssemblyLinearVelocity = (direction.Unit * strength)
		end
		
		print("Start2")
		task.wait(1)
		print("Can do 1")
		task.wait(ragTime)
		print("End")
		notRagdolled = true
		script.Parent:FindFirstChild("Torso"):SetNetworkOwner(player)
		
		script.Parent.HumanoidRootPart:PivotTo(script.Parent.Torso.CFrame)

		script.Parent.HumanoidRootPart.Position = Vector3.new(script.Parent.HumanoidRootPart.Position.X,script.Parent.HumanoidRootPart.Position.Y +0.5,script.Parent.HumanoidRootPart.Position.Z)

		script.Parent.HumanoidRootPart.Anchored = false

		script.Parent.HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero

		script.Parent.HumanoidRootPart:SetNetworkOwner(nil)

		script.Parent.HumanoidRootPart.AssemblyLinearVelocity = Vector3.zero

		script.Parent.HumanoidRootPart:SetNetworkOwner(player)

		for _, motor6d in ipairs(script.Parent:GetDescendants()) do
			if motor6d:IsA("Motor6D") then
				motor6d.Enabled = true
			end
		end

		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
		script.Parent.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)

		headBodyJoint.Enabled = false
		leftABodyJoint.Enabled = false
		rightABodyJoint.Enabled = false
		leftLBodyJoint.Enabled = false
		rightLBodyJoint.Enabled = false
		
		
	end
end

return ragdoll

Screenshot 2025-04-03 171333

That’s insanely cursed. Are you 100% sure that ragTime doesn’t get changed anywhere else?

1 Like

Nevermind. I see it’s used as a parameter.

Follow up: could you print what ragTime is just before the wait?

1 Like

Nope, I am very sure this isnt the case

Did that
image

…and replacing ragTime with 5 directly?

1 Like

Tried doing that, still doesn’t work
I made sure that it printed after setting it to 5

image

I also made it just wait 5 seconds without using ragTime, still didn’t work

That’s insane. Studio isn’t freezing either, is it?

1 Like

To debug and find out when the script stops, can you do this instead of waiting 5 seconds:

for i = 1, 50 do
    print("Still running at "..i/10.." seconds")t
    task.wait(0.1)
end
1 Like

It stopped working after a second

Well now you’ve got to figure out what makes it stop, if the script is still running, if other scripts are still running, if the function is still running…

(Try to see what corresponds to 1 second)

1 Like

Yep that was the exact problem I found. The script calling the modular script got deleted before it could finish

Thanks for the help though

2 Likes