0

I'm having a problem with my simple code, im new, heres the code:

local button = game.StarterGui.LoadingGui.MainCanvas.LoadingSequence.Elements.Skip.Button if button.MouseButton1Click then freemouse = false

end

The script should be connected to a button within the interface and it should disable free looking(off by default) when clicked, however as it is currently with this script, you can click anywhere and it will disable free looking, any help is appreciated, thanks.

I've tried to set the MouseButton1Click to a function, which did not resolve the problem.

2 Answers2

1

This is how you should use the MouseButton1Click event.

local button = game.Players.LocalPlayer.PlayerGui.LoadingGui.MainCanvas.LoadingSequence.Elements.Skip.Button

-- This function runs when you left click the button.
local function leftClick()
    -- do something here
    freemouse = false
    print("Left mouse click")
end

button.MouseButton1Click:Connect(leftClick) -- connect function

Vector3
  • 418
  • 2
  • 8
  • Connecting to the button instance in StarterGui will still not print anything when the button is clicked. You need to find the one in the PlayerGui – Kylaaa Jun 27 '23 at 23:10
  • 1
    @Kylaaa Oh yeah I forgot to update the path for the button. – Vector3 Jun 28 '23 at 20:39
0

You should use it as an event, not a boolean. The event fires a RBLXEventSignal on call, so you have to detect it using the Connect() function as stated below.

local button = game.Players.LocalPlayer.PlayerGui.LoadingGui.MainCanvas.LoadingSequence.Elements.Skip.Button

button.MouseButton1Click:Connect(function()
    -- do your code here on click
end)

First you refer to the event by doing button.MouseButton1Click, then you connect it into a function using :Connect() with the function inside. Within the function, you can insert your code on what you want to do with the event.

Happy coding!

zeyuan2009
  • 36
  • 4