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

How can I get a TextLabel to display the person who clicked a button?

Im trying to make it for when a person clicks a button in a GUI, there name will appear in the Frame.

3 comments

0

Use the MouseButton1Down event and change the player's name in it

0

I'm a bit confused when you say "Change the players name in it" What do you mean, I already have the MouseButton1Down event.

0

I meant change the GUI's text

2 answers

✓ Accepted answer

The person said they wanted a TextLabel to display the player's name, not the button that gets pressed!

local textlabel = somelabel
local button = thebutton

button.MouseButton1Click:connect(function(player)
	textlabel.Text = player.Name
end)

If you want it to display on a public server GUI, you probably wanna do somethin' like this

GLOBAL:

local textlabel = somelabel
local clickedEvent = game.ReplicatedStorage.clickedEvent -- You have to add a RemoveEvent to Replicated Storage
local players = game.Players

clickedEvent.OnServerEvent:connect(function(plr)
	plrchild = players:GetChildren()
	for i,v in pairs(plrchild) do
		local plrGUI = v:FindFirstChildOfClass("PlayerGui")
		textlabel = wherevertextlabelisinsideplayerGUI
		textlabel.Text = plr.Name
		wait()
	end
end)

LOCALSCRIPT:

local button = somebutton
local clickedEvent = game.ReplicatedStorage.clickedEvent

button.MouseButton1Click:connect(function()
	clickedEvent:FireServer()
end)
local playerValue = nil
local textbutton = script.Parent

textbutton.MouseButton1Down:Connect(function(player)
	playerValue = player
end

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