How to get player on mousebutton1click

i want to close a UI with a remote even whenever a player clicks the close button, but it wont get the player, how do i get the player? here is my code:

local button = script.Parent
local repstorage = game:GetService("ReplicatedStorage")
local paperendevent = repstorage:WaitForChild("PaperEndEvent")

button.MouseButton1Click:Connect(function(player)
	paperendevent:FireClient(player)
	
end)

this is the output
image

help would be very much apreciated

Because MouseButton1Click doesn’t provide a player instance.
Also use local scripts for UI instead of server scripts.

If you want to get a player object in a local script simply do:

game:GetService("Players").LocalPlayer

you cant fire client in local script

You can’t use a remote event on the client to interact with another client. Use bindable events for that instead.

whats that? could you please explain what bindable events are or just type the code so i can analyze what its doing. thank you

All information and documentation about Bindable Events can be found here: BindableEvent | Documentation - Roblox Creator Hub

You should read about this aswell: Client-Server Runtime | Documentation - Roblox Creator Hub

Actually replied here lol


so where do i put the bindable event in my code im still a bit confused

Explaining it in a simpler way, as you can see in this image:
image

What it is doing is sending the signal from the client to the server, and vice versa. I don’t know much about the differences between RemoteEvents and BindableEvents, but that’s what I understand. If I’m wrong, feel free to correct me.

I think the bindable event can be put anywhere, but i will put it inside the script that fires it, or in replicatedstorage, like this:

local button = script.Parent
local repstorage = game:GetService("ReplicatedStorage")
local paperendevent = --path to your bindable event

button.MouseButton1Click:Connect(function(player)
	paperendevent:FireClient(player)
	
end)

still wont close.
here is my local script:

local replicatedstore = game:GetService("ReplicatedStorage")
local paperendevent = replicatedstore:WaitForChild("paperendevent")
local player = game.Players.LocalPlayer

paperendevent.Event:Connect(function()
	if player.PlayerGui.ScreenGui.Enabled == true then
		player.PlayerGui.ScreenGui.Enabled = false
	else
		return nil
	end

end)

here is my script

local button = script.Parent
local repstorage = game:GetService("ReplicatedStorage")
local paperendevent = repstorage:WaitForChild("paperendevent")

button.MouseButton1Click:Connect(function(player)
	paperendevent:Fire(player)
	
end)

yes im clueless i dont know what im doing, never heard of bindable events never used them. doesnt work either so i dont know what to do.

I think you can’t connect a Local Script with a Server Script

RemoteEvents send signals from the client to the server (and vice versa). BindableEvents can only send signals from client to client (yourself) and server to server.

BindableEvents only have the :Fire() method rather than the context specific methods.

image

i cant do FireClient on the bindable event.

Oh, I understand, thanks for the correction :smiley:

Could you send the hierarchy of the button variable, aswell as explain what you’re trying to do?

I dont know what you mean with hierarchy, my native language isn’t english so im still learning, i think you mean this:
image
and i want to achieve whenever a player clicks the close button the UI closes on client side, cause i think if i just put it in a script and say ui.enable = true/false it would do it on all clients since i think scripts are server sided.