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

Make a clickbutton that opens only on a left click?

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?

1 comment

1

I'm reasonably sure you would have to make your own 'clickdetector' using Mouse.Target and Mouse.Button1Down

1 answer

✓ Accepted answer

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.

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