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

How to make a tool destroy a part with Click Detector on the Part?

I know that there a way to make it so if a player has a certain tool in their inventory, they can click on a "Part" that has a click detector on it with the key, which is the tool that I referenced above, in their Inventory.

What I am basically wanting to achieve is the player must find a key, pick it up, then bring it to said "Part" and click on it to unlock it, which in this case would be to run the event :Destroy(). Then this will allow the player to freely open and close the door.

I am fairly new to scripting and love figuring things out myself. I would just like to be pointed in a certain direction on how to do this since I am just now beginning with making tools and wanting to make something like this.

Thanks :)

1 answer

✓ Accepted answer
local Door = game.Workspace:WaitForChild("Door")
local Mouse = game.Players.LocalPlayer:GetMouse()

Mouse.Button1Down:Connect(
    function()
        local Target = Mouse.Target
        if Target == Door then
            for i, v in pairs(game.Players:GetPlayers()) do
                local character = v.Character

                character.ChildAdded:Connect(
                    function(tool)
                        if tool:IsA("Tool") then
                            if tool.Name == "Tool" then
                                Door:Destroy()
                            end
                        end
                    end
                )
            end
        end
    end
)

6 comments

0

It's weird because it won't work.. I changed character to game.Players in the first line and in the second line made it game.workspace..

0

are you trying to make this work for all parts

0

No. Could you add me on discord to talk about it? Thanks :) Ranger#0188

0

sure

0

sure

0

sure

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