Tool won't appear in backpack when clicked

i have a script where if you click on a tool that is in workspace, you pick it up and it’s supposed to appear in your inventory

the issue is, when i click the tool, it disappears and doesn’t appear in my inventory.

ive tried to use different scripts, but still the same issue reoccurs.

here is the script i use

local tool = script.Parent
local click = tool.ClickDetector
click.MouseClick:Connect(function(player)
	tool.Parent = player.Backpack
end)

it gives me an error in output too, here it is.

and when i click the error, it took me to the script i use that when i equip the tool, a UI opens which is what i need. this is my script for the tool when equipped a UI opens;

local Ui = script:WaitForChild("DrawGui")

script.Parent.Equipped:Connect(function()
	local ScreenGui = Ui:Clone()
	ScreenGui.Parent = game.Players.LocalPlayer.PlayerGui
end)

script.Parent.Unequipped:Connect(function()
	game.Players.LocalPlayer.PlayerGui:FindFirstChild(Ui.Name):Destroy()
end)

please help, i need this project done by today.

1 Like

try storing the clone of it in a variable, destroy the original, put the replica inside the player’s backpack


well, .Equipped works on tools, and script.Parent seems to be handle, try doing script.Parent.Parent (assuming the handle is inside the tool)

i tried to do script.parent.parent and the tool didnt respond, not disappearing nor going into my backpack. also can u give me an example on how to do what u said on the top im kinda new to scripting and have no idea how to store a clone of it in a variable and stuff

programming is a world of magic, can i see your tool in the explorer or something (gonna try to find the cause of this), additionally i’m gonna ask if all the parts in your tool are welded together (not anchored)


uhhhh

local clonedTool = originalTool:Clone()
originalTool:Destroy()
clonedTool.Parent = player.Backpack

where do i put this
and this is where i put my tool
image_2024-06-25_000533149

the folder is in workspace, by the way

uh you put that in clicktopickup inside the .MouseClick event

click.MouseClick:Connect(function(player)
	local clonedTool = originalTool:Clone()
    originalTool:Destroy()
    clonedTool.Parent = player.Backpack
end)

do i replace the tool.Parent = player.Backpack with the script u gave, or do i add it under the already existing line inside the .mouseclick event

yeah you replace that

character limit character limit wetjoiajjhroghsaoughfsdpugd

1 Like

i replaced the “tool.Parent = player.Backpack” under the mouseclick event and it showed me this error when i tried to click it.

this is also how the script looks with it idk if i did something wrong
image

boy what the hell boy

replace originalTool with your tool variable

originalTool is your actual tool variable!!!

opps LOL mb rgfKJEWLGEQTHBQEHBL CHARACRTER

replace

script.Parent.Equipped

with

script.Parent.Parent.Equipped

You’re referencing the handle which doesn’t have the equipped property. It should be the tool which I assume is the parent of the handle

Edit: Oops, sorry. I didn’t realize you already tried it

2 Likes

wait

why do you have 2 functions :face_with_raised_eyebrow:

that’s not the way to do it :slightly_frowning_face:

click.MouseClick:Connect(function(player)
local clonedTool = tool:Clone()
tool:Destroy()
clonedTool.Parent = player.Backpack

Hopper bins may help you with this

1 Like

i am a little dumb uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh one minute please :hugs:

1 Like

what is a hopper bin and what do they help with

so uh i fixed it up and everything and when i click it doesnt do anything and nothing appears in output :sob:

It’s a hopping bin and it can hop into your backpack

what is this space alien problem

can you put a print("i have been clicked and i do not work!") right at the start of that function


oh wait, looking at the explorer rn

the parent of the click script is Handle right?

try doing tool = script.Parent.Parent instead, otherwise that code will only run upon clicking the handle (Which is bad!!!)