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

How do i change text to players name?

Asked by 3 years ago
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

Log in to vote
1
Answered by
Aztralzz 169
3 years ago

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!

0
oh ok thanks , i retried alot of times and forgot to use .name lol. Thanks and btw im not making a game RebornedSnoop 175 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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
Log in to vote
-2
Answered by 3 years ago

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)

Answer this question