I am trying to make a door that will close when a person with a certain tool clicks on a button. Only one player will have the tool, and they should have it equipped at all times. I can't get the button to work when the tool is equipped.

As of now, it is a part with a click detector inside. I'm not sure if I'm supposed to use MouseButton1Click for this.

local button = script.Parent
door1 = workspace.Doors.Door1

function onClicked(playerWhoClicked)
    local tools = playerWhoClicked.Backpack:GetChildren() 
    for i, tool in pairs(tools) do
        if tool.Name == "MakeItRain" then 
            door1.Transparency = .2
            door1.CanCollide = true
        end
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

5 comments

0

Mouse click is correct. I don't think you can activate click detectors with gear, and instead of doing a pairs it's simple just do, "playerWhoClicked.Backpack.MakeItRain".

0

Thanks. Would it work with a surface gui?

0

You should write this into the tool itself and use the Target property and Button1Down event of the mouse and to see what object is clicked.

0

That sounds hard. I guess I could try.

0

Remote Event? Idk on this.