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'.
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)