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
5 years ago
Edited 5 years ago

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)

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

1 answer

Log in to vote
0
Answered by 5 years ago

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

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

Answer this question