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

Is there a way to check for left click with a click detector and refuse a right click?

Asked by 7 years ago

I'm trying to turn this script

local clickDetector = script.Parent
local buttonPressed = false
local ClickModule = require (game:GetService("ServerScriptService").ModuleScript)

local OnClick
OnClick = clickDetector.MouseClick:connect(function(Clicker)
    if not buttonPressed then   
        buttonPressed = true
            ClickModule(Clicker, script.Parent.Parent)
        wait()
        buttonPressed = false
    end
end)

into a left click only detector. I've tried

local clickDetector = script.Parent
local buttonPressed = false
local ClickModule = require (game:GetService("ServerScriptService").ModuleScript)

local OnClick
OnClick = clickDetector.MouseClick:connect(function(Clicker)
    if not buttonPressed then   
        buttonPressed = true
        local Mouse = Clicker:GetMouse()
        local event
        event = Mouse.Button1Down:connect(function()
            ClickModule(Clicker, script.Parent.Parent)
        end)
        wait()
        buttonPressed = false
        event:disconnect()
    end
end)

and it works in studio, but once i run the server, the mouse returns nil and the script doesnt run.

0
You could try this method, although it might require the use of Remote Events. https://scriptinghelpers.org/questions/30209/using-getmouse-instead-of-clickdetector User#11440 120 — 7y

Answer this question