How to see what player clicked a gui button?

Oh, that works. Thanks! I was probably just thinking too difficult…

Make sure to press the checkmark on my post with the code so people know its solved

Make sure to press the checkmark on my post with the code so people know its solved.

This works but it’s very inefficient (you’re indexing a lot of instances in order to reach the desired “TextButton” instance).

Secondly, the “MouseButton1Click” event of TextButton/ImageButton GuiObjects does not pass the player instance as an argument to any callback function connected to it via the instance method “:Connect()”.

Here’s how this code should be written.

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = workspace.CurrentCamera

local ExitButton = script.Parent

ExitButton.MouseButton1Click:Connect(function()
	ExitButton.Visible = false
	Camera.CameraSubject = Humanoid
end)

image

You should avoid referencing instances from within the “PlayerGui” folder if possible and instead use local scripts parented to the GuiObject instances themselves.

I didn’t even reference startergui. I referenced player gui.

Typo on my end, I meant you shouldn’t refer to instances from within the “PlayerGui” when it can be avoided.