I'm trying to make a left mouse detector on a clickdetector so you cant accidently right click it, and am using
local clickDetector = script.Parent local buttonPressed = false function OnClick(Clicker) if not buttonPressed then buttonPressed = true local Mouse = Clicker:GetMouse() print("gotMouse") Mouse.Button1Down:connect(function() print("Left Click") end) wait(0.2) buttonPressed = false end end clickDetector.MouseClick:connect(OnClick)
but I cant figure out how to make a :disconnect() work or anything. Please help
What you need to do is obtain a reference to the RBXScriptConnection returned by connecting your function to the event. With that reference, you can disconnect() it so the connected function doesn't run again in the future. Here's an example from the wiki:
local con con = Part.Touched:connect(function(hit) con:disconnect() print("Collided with " .. hit.Name) end)
In that example, the connected function will only be executed once, because it disconnects the connection immediately after the part is touched. You can apply the same concept to the Button1Down event. For more information, visit the wiki: http://wiki.roblox.com/index.php?title=RBXScriptSignal#RBXScriptConnection