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

How do i change text to players name?

local player = game:GetService("Players")
local plr = player.LocalPlayer
local GUI = game.StarterGui.ScreenGui.TextLabel

player.PlayerAdded:Connect(function()
GUI.Text = plr
end)

When I put "" to the plr then it will change the text to plr. But when I remove the "" it will give me a bad argument error. So does anybody know how to change text to a variable? The plr variable means "RebornedSnoop" which is me but it doesnt change like a normal text. Sorry I cant explain very well. But please help if you understand. Thanks.

3 answers

✓ Accepted answer

You can get the localplayers name using plr.Name. Here's an example:

local player = game:GetService("Players")
	local plr = player.LocalPlayer
	local GUI = game.StarterGui.ScreenGui.TextLabel
	 
	player.PlayerAdded:Connect(function()
	GUI.Text  = plr.Name -- Name get's the local players name, that simple
	end)

Really simple, good luck with your game!

1 comment

0

oh ok thanks , i retried alot of times and forgot to use .name lol. Thanks and btw im not making a game

Put a LocalScript inside of the TextLabel and write this.

script.Parent.Text = game.Players.LocalPlayer.Name

You do not and cannot use game.Players.PlayerAdded in a LocalScript, since it runs on the client and not the server.

And if you're going to change any gui through a server, you have to use PlayerGui.

game.Players.PLAYER_NAME_HERE.PlayerGui.ScreenGui.Frame.TextLabel.Text

Try changing the StarterGui to PlayerGui

local player = game:GetService("Players")
local plr = player.LocalPlayer
local GUI = game.PlayerGui.ScreenGui.TextLabel

player.PlayerAdded:Connect(function()
GUI.Text = plr
end)

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