Print not working after Wait()

Yeah but if it doesn’t work without the wait then the wait isn’t the issue maybe. Not sure what else it could be maybe the function is being overridden during the wait time. You could try using task.delay

As @TheDCraft said, does it work without the wait?

@TheDCraft , @STORMGAMESYT7IP I just tried. It does work without wait(). But with wait it doesn’t. I even added a debounce to the whole function so that it doesn’t get fired multiple times until everything inside it is finished. Still, with wait it doesnt work. Let me post here the whole script and the script where it calls the function

This is the Module Script inside ServerScriptService

local Module = {}
local RE = game.ReplicatedStorage.Ragdoll
local PS = game:GetService("PhysicsService")
local ragDB = false

Module.Ragdoll = function(char,bool)
	
	if ragDB == false then
		ragDB = true
		local plr = game.Players:GetPlayerFromCharacter(char)
		if char.Humanoid.Health~=0 and ((char:FindFirstChild'LowerTorso'and not char.LowerTorso.Root.Enabled)or (char:FindFirstChild'Torso'and not char.Torso.Neck.Enabled)) and not bool then
			RE:FireClient(plr,false)
			for _,v in pairs(char:GetDescendants()) do
				if v:IsA'Motor6D' then
					v.Enabled = true
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = false
				end
			end
		else
			RE:FireClient(plr,true)
			for _,v in pairs(char:GetDescendants()) do
				if v:IsA'Motor6D'and Module.Check(v.Name)then
					v.Enabled = false
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = true
				elseif v.Name=="Head"then
					local b = Instance.new("BodyVelocity",char.Head)
					b.Velocity = Vector3.new(math.random(-10,10),0,math.random(-10,10))
					wait(0.1)
					b:Destroy()
				--[[task.spawn(function()
					wait(.1)
					b:Destroy()
				end)--]]
				end
			end
			print("Bef")
			task.wait(3)
			print("Aft")
			RE:FireClient(plr,false)
			for _,v in pairs(char:GetDescendants()) do
				if v:IsA'Motor6D' then
					v.Enabled = true
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = false
				end
			end
		end
		ragDB = false
	end
	
end

Module.Bot = function(bot)
	task.spawn(function()
		local H = bot.Humanoid
		if bot:FindFirstChild'HumanoidRootPart'and H.Health~=0 and bot:FindFirstChild'LowerTorso' and bot.LowerTorso.Root.Enabled==true then
			H:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
			H:ChangeState(Enum.HumanoidStateType.Ragdoll)
			for _,v in pairs(H:GetPlayingAnimationTracks())do v:Stop(0)end
			bot.Animate.Disabled = true
			
			for _,v in pairs(bot:GetDescendants()) do
				if v:IsA'Motor6D'and Module.Check(v.Name) then
					v.Enabled = false
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = true
				end
			end
			wait(10)

			bot.Animate.Disabled = false
			H:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
			H:ChangeState(Enum.HumanoidStateType.GettingUp)

			for _,v in pairs(bot:GetDescendants()) do
				if v:IsA'Motor6D' then
					v.Enabled = true
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = false
				end
			end
		end
	end)
end

Module.Check = function(t)
	for _,v in pairs({"LeftWrist","RightWrist","LeftAnkle","RightAnkle"}) do
		if v == t then return false end
	end
	return true
end

Module.Joints = function(c)
	c.Humanoid.BreakJointsOnDeath = false
	c.Humanoid.RequiresNeck = false
	for _,v in pairs(c:GetDescendants()) do
		if v:IsA("Motor6D")and Module.Check(v.Name)then
			local b = Instance.new("BallSocketConstraint",v.Parent)
			local a0,a1 = Instance.new("Attachment"),Instance.new("Attachment")
			a0.Parent,a1.Parent = v.Part0,v.Part1
			b.Attachment0,b.Attachment1 = a0,a1
			a0.CFrame,a1.CFrame = v.c0,v.c1
			b.LimitsEnabled = true
			b.TwistLimitsEnabled = true
			b.Enabled = false
		elseif v:IsA'BasePart' then
			PS:SetPartCollisionGroup(v,"A")
			if v.Name == "HumanoidRootPart" then
				PS:SetPartCollisionGroup(v,"B")
			elseif v.Name=="Head"then
				v.CanCollide = true
			end
		end
	end
end

return Module

And this is the script where I call the function

local boulder = script.Parent
local M = require(game.ServerScriptService.Module)
local prevHits = {}


boulder.Touched:Connect(function(hit)
	
	if hit.Parent:FindFirstChild("Humanoid") and not prevHits[hit.Parent.Name] then
		
		table.insert(prevHits, hit.Parent.Name)
		M.Ragdoll(hit.Parent, true)
		
		
	end
	
end)

try removing wait(3), if it prints aft then it’s the wait issue if it doesn’t, then idk

You could try this:

task.delay(3, function()
   RE:FireClient(plr,false)
   for _,v in pairs(char:GetDescendants()) do
   if v:IsA'Motor6D' then
      v.Enabled = true
    elseif v:IsA'BallSocketConstraint' then
      v.Enabled = false
   end
end)

Tried it, doesn’t work. I put a print function too right at the beginning at task.delay(), still nothing

Try wrapping everything inside the if statement in a coroutine (except the first line ragDB = true). I’ve had issues with waiting in module scripts in the past and that’s how i solved it

I have no idea how coroutines work, never used them before. Could you please show how?

Hopefully this shouldn’t mess up the debounce since it’s after it changes

Module.Ragdoll = function(char,bool)
	
	if ragDB == false then
		ragDB = true
		coroutine.resume(coroutine.create(function()
		local plr = game.Players:GetPlayerFromCharacter(char)
		if char.Humanoid.Health~=0 and ((char:FindFirstChild'LowerTorso'and not char.LowerTorso.Root.Enabled)or (char:FindFirstChild'Torso'and not char.Torso.Neck.Enabled)) and not bool then
			RE:FireClient(plr,false)
			for _,v in pairs(char:GetDescendants()) do
				if v:IsA'Motor6D' then
					v.Enabled = true
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = false
				end
			end
		else
			RE:FireClient(plr,true)
			for _,v in pairs(char:GetDescendants()) do
				if v:IsA'Motor6D'and Module.Check(v.Name)then
					v.Enabled = false
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = true
				elseif v.Name=="Head"then
					local b = Instance.new("BodyVelocity",char.Head)
					b.Velocity = Vector3.new(math.random(-10,10),0,math.random(-10,10))
					wait(0.1)
					b:Destroy()
				--[[task.spawn(function()
					wait(.1)
					b:Destroy()
				end)--]]
				end
			end
			print("Bef")
			task.wait(3)
			print("Aft")
			RE:FireClient(plr,false)
			for _,v in pairs(char:GetDescendants()) do
				if v:IsA'Motor6D' then
					v.Enabled = true
				elseif v:IsA'BallSocketConstraint' then
					v.Enabled = false
				end
			end
		end
		ragDB = false
		end))
	end
	
end

Can you format you code properly paste it in studio then paste it here again. its confusing

The code is properly formatted, what are you talking about?

image

It still didn’t work. And I realised that using debounce in this module script is probably not a good idea, cuz many players may get ragdolled at the same time, and then because of debounce it will work only for one of them, right?

Yep, you’d have to store debounce for each player separately in a table i guess

1 Like

Is that work when you destroy wait(3)?

Another problem i had with modules was when i was waiting for remote functions and events. Try moving the second line in the script (local RE = game.ReplicatedStorage.Ragdoll) to the first line of the function for example.

Doesn’t work. Also tried doing WaitForChild() for the remote event. Still nothing

My Ragdolled character is reflecting my emotional state after being baffled by this issue for 5 hours.

I’m curious, try this and see what it prints out:

print("Bef")

for i = 1,3 do
	task.wait(1)
	warn("WAITED " .. i .. " OUT OF 3")
end

print("Aft")
1 Like