Remote event on button?

So if I do this will the player only beable to click on the button after the remote event is fired?:

RemoteEvent.OnClientEvent:Connect(function()
	Button.MouseButton1Up:Connect(function()
        -- something
    end)
end)

I’d imagine so, you can always disconnect the listener later by doing

local connection
RemoteEvent.OnClientEvent:Connect(function()
	connection = Button.MouseButton1Up:Connect(function()
        -- something
    end)
end)

function stopListening()
	connection:Disconnect()
end
1 Like

Yeah, the button click event MouseButton1Up will only be triggered when the OnClientEvent of the RemoteEvent is fired. The Button.MouseButton1Up:Connect function is inside the OnClientEvent:Connect callback, so it will only be activated when the remote event is triggered on the client side.

1 Like

So if I fire it at the begin of the players join they will be able to press it their whole stay

yeah with just this code you’ve provided I can pretty much assume that.

Just make sure that this event isn’t being fired more than once or you’ll be creating multiple instances of button events. You’ll also probably want to use MouseButton1Click as well as OnClientEvent:Once() or OnclientEvent:Wait().

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.