Pick up system not working on characters, but working on everything else

  1. What do you want to achieve?

I’m trying to create a pick up system that lets players pick up items and other players.

  1. What is the issue?

The pick up system works for objects, however doesn’t work for players. Here is the script that is placed under each object and under each player:

clickDetector = script.Parent
holding = false
part = clickDetector.Parent
charHolding = nil

clickDetector.MouseClick:Connect(function(player)
	
	local char = player.Character
	
	if holding == false and char.Holding.Value == false then
		
		part.Weld:Destroy()
		local newWeld = Instance.new("Weld")
		newWeld.Part0 = part
		newWeld.Part1 = char.HoldPartPositionHolder
		newWeld.Parent = part
		newWeld.Name = "Weld"
		part.Position = char.HoldPartPositionHolder.Position
		holding = true
		char.Holding.Value = true
		charHolding = char
		
	else if holding == true then
		
		part.Weld:Destroy()
		local newThing = Instance.new("Weld")
		newThing.Name = "Weld"
		newThing.Parent = part
		holding = false
		charHolding.Holding.Value = false
			
	end
		
	end
	
end)

The script doesn’t error, it just does nothing when I click the player. Here’s the hierarchy for the player:
image

Any help would be appreciated!

2 Likes

There is a syntax error in this code.

Instead of “else if”, the correct syntax is “elseif”.

The corrected code is:

clickDetector = script.Parent
holding = false
part = clickDetector.Parent
charHolding = nil

clickDetector.MouseClick:Connect(function(player)
	
	local char = player.Character
	
	if holding == false and char.Holding.Value == false then
		
		part.Weld:Destroy()
		local newWeld = Instance.new("Weld")
		newWeld.Part0 = part
		newWeld.Part1 = char.HoldPartPositionHolder
		newWeld.Parent = part
		newWeld.Name = "Weld"
		part.Position = char.HoldPartPositionHolder.Position
		holding = true
		char.Holding.Value = true
		charHolding = char
		
	elseif holding == true then
		
		part.Weld:Destroy()
		local newThing = Instance.new("Weld")
		newThing.Name = "Weld"
		newThing.Parent = part
		holding = false
		charHolding.Holding.Value = false
			
	end
		
end)

It never errored in the first place, but I put your code in and it still didn’t work.

You try to have the Value of a inexistant instance.
You want Hitbox.Holding, right?
There is the solution:

clickDetector = script.Parent
holding = false
part = clickDetector.Parent
charHolding = nil

clickDetector.MouseClick:Connect(function(player)

	local char = player.Character

	if holding == false and char.Hitbox.Holding.Value == false then

		part.Weld:Destroy()
		local newWeld = Instance.new("Weld")
		newWeld.Part0 = part
		newWeld.Part1 = char.HoldPartPositionHolder
		newWeld.Parent = part
		newWeld.Name = "Weld"
		part.Position = char.HoldPartPositionHolder.Position
		holding = true
		char.Hitbox.Holding.Value = true
		charHolding = char

	else if holding == true then

			part.Weld:Destroy()
			local newThing = Instance.new("Weld")
			newThing.Name = "Weld"
			newThing.Parent = part
			holding = false
			charHolding.Hitbox.Holding.Value = false

		end

	end

end)

I put the new code in and it doesn’t error, but it also doesn’t work.

I solved the issue of not being able to pick up the NPC character, the code worked. The problem was that I had not welded the hitbox to the torso. Thanks for helping though!

1 Like

I was going to say it XDDDDD :smile:.

1 Like

Thank you!

Love that you’re returning the solution to the dev forum as people will have the same issue and find the solution here! +1

No problem! I’ve found old devforum posts helpful in the past also.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.