AkroThorn
(AkroThorn)
April 9, 2023, 2:31pm
#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.
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:
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)
AkroThorn
(AkroThorn)
April 9, 2023, 6:53pm
#3
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)
AkroThorn
(AkroThorn)
April 9, 2023, 6:58pm
#5
I put the new code in and it doesn’t error, but it also doesn’t work.
AkroThorn
(AkroThorn)
April 9, 2023, 7:01pm
#6
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 .
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
AkroThorn
(AkroThorn)
April 9, 2023, 7:52pm
#9
No problem! I’ve found old devforum posts helpful in the past also.
1 Like
system
(system)
Closed
April 23, 2023, 7:52pm
#10
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.