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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
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
)

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.. XRangerGuyX 29 — 4y
0
are you trying to make this work for all parts raid6n 2196 — 4y
0
No. Could you add me on discord to talk about it? Thanks :) Ranger#0188 XRangerGuyX 29 — 4y
0
sure raid6n 2196 — 4y
View all comments (2 more)
0
sure raid6n 2196 — 4y
0
sure raid6n 2196 — 4y
Ad

Answer this question