Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago

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)
0
Thank you! ercleric 24 — 2y
Ad

Answer this question