Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

For Button GUI's, Is There A Way to Get a Players Name From It?

Is there a way to get the player’s name from clicking a GUI? I’m trying to do a simple script that whenever you click on the button, it will print the person who clicked it name on the screen. I tried doing a function, and in the brackets put ‘player’. However when printing player.Name it comes out as nil? I know you can do script.Parent.Parent till you get to the player's name, however I'm wondering if there is a more efficient way.

Edit: Didn't know you could 'Inline code'.

1 answer

✓ Accepted answer

I think this should work

local button = script.Parent
local Players = game:GetService("Players")

button.Activated:Connect(function()
	local playerName = Players.LocalPlayer.Name -- Get player's name
	-- Do what you want with the name
end)

1 comment

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.