Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[SOLVED] ClickDetector stops working. Whats wrong?

Hi. I have this script in a tool to make it "Click to pickup"


local destroyMe = script.Parent:WaitForChild("Handle"):FindFirstChild("TouchInterest")
local tool = script.Parent


if destroyMe then

	destroyMe:Destroy()

end

script.Parent.ClickDetector.MouseClick:Connect(function(plr)

	tool.Parent =  plr.Backpack

end)

And it works! But when i drop tool from Backpack ("tool.Parent = game.Workspace") ClickDetector not detecting any clicks anymore. Am i doing something wrong?

Thanks guys ;)


SOLUTION Before adding tool to backpack, make it parent nil!

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	tool.Parent = nil
	tool.Parent =  plr.Backpack

end)


5 comments

0

I tried out your code, and it seems to be working fine for me. Any other details we should know?

0

I Found some useful info. If you drop it using backspace it works. I use Custom inventory, so tool is "CanBeDropped = false" and i drop it through script (Change its parent to workspace) and it stops working

0

Interesting. Give me a few minutes and I'll see what I can find out for you. I see what you're talking about.

0

I was messing around with your script and noticed that even once the object was placed back in the Workspace by a script, it was stating that it was a child of the player's backpack still. One thing you could do, potentially, is set the tool's parent to nil and then to the player's backpack. That worked for me, though I don't know how efficient that is.

0

Oh! Thanks for info! It worked for me)

1 answer

What you want to do is clone the tool:

local Handle = script.Parent:WaitForChild("Handle")
local Destroyme = Handle:FindFirstChild("TouchInterest")
local ClickDetect = script.Parent:WaitForChild("ClickDetector")
local Tool = script.Parent

if Destroyme then
	Destroyme:Destroy()
end

ClickDetect.MouseClick:Connect(function(plr)
	local Clone = Tool:Clone()
	Clone.Parent = plr.Backpack
end

This clones the tool into the players backpack. Its advised you add some security mesures so they cant pick up multiple items which would be to check if they have it with if plr.Backpack:FindFirstChild(Tool.Name) then return end

3 comments

0

It appears, to me at least, that he would prefer an object to be removed from the Workspace once it is clicked. More of a "pick up" option than a tool giver.

0

Then you can call Tool:Destroy()

0

or Tool.Parent = game:GetService("ReplicatedStorage")

This discussion is preserved as it was. New answers, comments, and votes are closed.