Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[SOLVED] ClickDetector stops working. Whats wrong?

Asked by
vovik 9
6 years ago
Edited 6 years ago

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


01local destroyMe = script.Parent:WaitForChild("Handle"):FindFirstChild("TouchInterest")
02local tool = script.Parent
03 
04 
05if destroyMe then
06 
07    destroyMe:Destroy()
08 
09end
10 
11script.Parent.ClickDetector.MouseClick:Connect(function(plr)
12 
13    tool.Parent =  plr.Backpack
14 
15end)

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!

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

end)

0
I tried out your code, and it seems to be working fine for me. Any other details we should know? Rocketerkid 237 — 6y
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 vovik 9 — 6y
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. Rocketerkid 237 — 6y
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. Rocketerkid 237 — 6y
0
Oh! Thanks for info! It worked for me) vovik 9 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

What you want to do is clone the tool:

01local Handle = script.Parent:WaitForChild("Handle")
02local Destroyme = Handle:FindFirstChild("TouchInterest")
03local ClickDetect = script.Parent:WaitForChild("ClickDetector")
04local Tool = script.Parent
05 
06if Destroyme then
07    Destroyme:Destroy()
08end
09 
10ClickDetect.MouseClick:Connect(function(plr)
11    local Clone = Tool:Clone()
12    Clone.Parent = plr.Backpack
13end

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

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. Rocketerkid 237 — 6y
0
Then you can call Tool:Destroy() Protogen_Dev 268 — 6y
0
or Tool.Parent = game:GetService("ReplicatedStorage") Protogen_Dev 268 — 6y
Ad

Answer this question