I was looking at some code that I wrote in the past, and it never occurred to me before that the button that it belongs to can be opened using either the left or right mouse button. Here's the code
function BarrierBreak() game.Workspace.Barrier:Destroy() game.Workspace.BarrierBreaker:Destroy() end script.Parent.ClickDetector.MouseClick:connect(BarrierBreak)
How can I make the button only run the function on a left click?
You'd probably want to make a local script that handles the interaction, like the comment mentioned. It could look something like this:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local barrier = game.Workspace.PathToBarrier function MouseClick() local target = mouse.Target if target == barrier then target:Destroy() target:Destroy() end end mouse.Button1Up:connect( MouseClick )
Now, instead of statically defining the barrier, you'd probably want to check it by it's name, or have some special value placed into the barrier, that would help the script recognize if it's a barrier.