What does this error mean, and how can I stop it from happening?

  1. What do you want to achieve? A ragdoll script that ragdolls whoever touched the part

  2. What is the issue? in my module script that handles the RagdollFunctions I get an error that says Expected BasePart got WrapTarget for Weld:Part1. when I try to weld the head and lower torso to the humanoidRootPart.

  3. What solutions have you tried so far? I’ve looked at the wrap target API yet it didn’t provide any possible solutions.

here’s the module script:


local RagdollFunctions = {}

RagdollFunctions.Ragdoll = function(random, char, player) -- ragdoll function
	
	game.ReplicatedStorage.RagdollEvent:FireClient(player, "Ragdoll") -- fire an event to the client
	
	char.Humanoid.JumpPower = 0
	
	for _, v in pairs(char:GetDescendants()) do
		if v:IsA("BasePart") and v.Name == "Head" or v.Name == "LowerTorso" then
			local weld = Instance.new("Weld")
			weld.Part0 = char.HumanoidRootPart
			weld.Part1 = v -- part where it errors
			weld.C0 = char.HumanoidRootPart.CFrame:Inverse()
			weld.C1 = v.CFrame:Inverse()
			weld.Parent = char.HumanoidRootPart
		end
		
		if v:IsA("Motor6D") then
			local attachment0 = Instance.new("Attachment")
			local attachment1 = Instance.new("Attachment")
			
			attachment0.Name = "Attachment0"
			attachment1.Name = "Attachment1"
			
			attachment0.CFrame = v.C0
			attachment1.CFrame = v.C1
			attachment0.Parent = v.Part0
			attachment1.Parent = v.Part1
			
			local constraint = Instance.new("HingeConstraint")
			
			constraint.Attachment0 = attachment0
			constraint.Attachment1 = attachment1
			constraint.Parent = v.Part0
			
			v:Destroy()
		end
	end
	
end



RagdollFunctions.Stand = function(random, char, player, humanoid) -- standing function
	
	humanoid.JumpPower = 50
	
	for _, v in pairs(char:GetDescendants()) do
		if v.Name == "Attachment0" or v.Name == "Attachment1" or v:IsA("Weld") or v:IsA("HingeConstraint") then 
			v:Destroy()
		end
	end
	
	humanoid:BuildRigFromAttachments() -- very handy function
	game.ReplicatedStorage.RagdollEvent:FireClient(player, "Stand")
	
end


return RagdollFunctions

all help is greatly appreciated

I’m not sure on the exact error but I do see one problem with this if statement.

if ((v:IsA("BasePart") and v.Name == "Head")) or ((v.Name == "LowerTorso")) then

Pretty much, the script thinks these conditions are separate (I wrapped the conditions around in parenthesis) meaning that any instance named ‘LowerTorso’ does not have to be a BasePart. Maybe there is a WrapTarget instance that has the name ‘LowerTorso’. You should try this instead.

if v:IsA("BasePart") and v.Name == "Head" or v:IsA("BasePart") and v.Name == "LowerTorso" then
2 Likes

The second version worked properly, thank you so much! I’m trying to find anything aside from the LowerTorso with the same name to find the source of the error but nothing seems to pop up, it’s so weird.

1 Like