How can I get a playerobject using mousebutton1?

Im trying to find the player using mousebutton1 so I can use :FireClient()

Ive already tried to add “player” to the function but it doesent work.

This is all the code i feel like you need to know:

script.Parent.MouseButton1Click:Connect(function(player)
	PauseEffect:FireClient(player)
end)

I edited this to say that im using server if you couldent tell.
The script is under a gui button if anyone couldent tell

1 Like

Is script.Parent a ClickDetector or what?

Mousebutton1click is (as i seen) is only used in gui buttons

1 Like

You should be connecting this on client and not on server.

I changed it to client to try and make it work but when i did the 2 parts i was Unanchoring (not shown in the script) wouldent work.

MouseButton1Click is only for GuiButtons. Not sure if Roblox replicates the event to the server but even if it does you should never detect it on the server.

I see the confusion with it being a clickedetector but its a gui button with a server script

The only way to Connect to a GuiButton event on the server is by accessing it through the player object. Which means you already know the player.

Example

-- Server Script
game.Players.thebeeninja5000.PlayerGui.ScreenGui.TextButton.MouseButton1Click:Connect()
-- here you already know the player who's PlayerGui you are accessing

That being said you should never run Gui code on the server in my opinion. The Gui is exclusive to the client and Roblox replicates it for some reason. But just because they replicate it doesn’t mean it’s good practice to edit it on the server.


What you do is you detect all Gui related things on the client and then send the information to the server with a RemoteEvent.

I made the script client added and removed abit of code and it FINALLY works. Thanks for helping me

1 Like

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