Asttempt to index nil with 'GetDescendants'

Hi, i have this ragdoll module in StarterCharacterScripts. It was working fine until today, where I have this error:

Code:

function Module:Ragdoll(Client)
	if not Client.Character then
		warn("[RAGDOLL]: Argument 1 (Model) not provided.")
		return
	end
	Client.Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)

	Player = Client;
	Model = Player.Character;
	Humanoid = Model.Humanoid;
	DespawnTime = SettingsModule["DEFAULTDESPAWNTIME"];
	Constraint = SettingsModule["DEFAULTCONSTRAINT"];
	CanDespawn = SettingsModule["DESPAWNENABLED"];
	CanRecover = SettingsModule["CANRECOVER"];
	LimitsEnabled = SettingsModule["LIMITSENABLED"];
	DespawnType = SettingsModule["DESPAWNTYPE"];

	DetectRig() 
end

-- cut out a lot of code that doesn't matter
function Unragdoll()
	for i, v in pairs(Model:GetDescendants()) do
		if v:IsA("Motor6D") then
			v.Enabled = true
		end
		if v:IsA("WeldConstraint") or v:IsA("HingeConstraint") or v:IsA("BallSocketConstraint") then
			Debris:AddItem(v , 0)
		end
		if v.Name == "RagdollAttachment" 
			or v.Name == "WaistRightAttachment"
			or v.Name == "WaistLeftAttachment"
		then
			Debris:AddItem(v , 0)
		end
		if v:IsA("NoCollisionConstraint") and v.Name == "RagdollNCC" then
			Debris:AddItem(v , 0)
		end
	end
	
	Model.HumanoidRootPart.CanCollide = true

	if Player then
		Humanoid.PlatformStand = false
		Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		SettingsModule.EVENTLOCATION:FireClient(Player, Model, Humanoid, true)
	end
	return true
end

Any help would be appriciated, thanks!

1 Like

Are you sure the variable ‘Model’ is loaded at the time of the function call?

You could try doing:

function Unragdoll(Model) -- When calling Unragdoll(), add the variable. Something such as Unragdoll(Model)
	for i, v in pairs(Model:GetDescendants()) do
		if v:IsA("Motor6D") then
			v.Enabled = true
		end
		if v:IsA("WeldConstraint") or v:IsA("HingeConstraint") or v:IsA("BallSocketConstraint") then
			Debris:AddItem(v , 0)
		end
		if v.Name == "RagdollAttachment" 
			or v.Name == "WaistRightAttachment"
			or v.Name == "WaistLeftAttachment"
		then
			Debris:AddItem(v , 0)
		end
		if v:IsA("NoCollisionConstraint") and v.Name == "RagdollNCC" then
			Debris:AddItem(v , 0)
		end
	end
	
	Model.HumanoidRootPart.CanCollide = true

	if Player then
		Humanoid.PlatformStand = false
		Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		SettingsModule.EVENTLOCATION:FireClient(Player, Model, Humanoid, true)
	end
	return true
end

Yes, the character is fully loaded.

Could you try printing the model variable at the top of the UnRagdoll function?

That should let you know what the issue is.