Is there anyway to check which player click a gui button?

Is there anyway to check which player click a GUI button?

You mean a specific player’s account? Or a player that’s playing your game?

.MouseButton1Click works on client-side. So, if you’d like to get the player instance on server-side, then you should use a RemoteEvent.

-- Client side
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

TextButton.MouseButton1Click:Connect(function()
	RemoteEvent:FireServer()
end)

-- Server side
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnServerEvent:Connect(function(Player: player)
	print(string.format("%s clicked the button", Player.Name))
end)

But how will this send in the player I don’t understand?

here is the script by the way!

local button = script.Parent

button.MouseButton1Click:Connect(function(player)
	print(player)
	local OldCharacter = player.Character
	local NewCharacter = game.ReplicatedStorage.Civilan:Clone()
	
	NewCharacter:SetPrimaryPartCFrame(OldCharacter.PrimaryPart.CFrame)
	
	player.Character = NewCharacter
end)

Basically in roblox UI mainly runs via the client (AKA the player)
so if someone presses that button, its going to be the local player, which can be got via:

game.Players.LocalPlayer -- This only works on the client btw

This is all assuming you are using a local script for your code, if you aren’t, please do use a local script.

This might help give you and understanding on this sorta thing:

here is the only problem this is meant to change the players character and with a local script will everyone see that character?

No, you’ll have to use a remote event to let the server change the player’s character which then will replicate to everyone else as well.