1 | local player = game:GetService( "Players" ) |
2 | local plr = player.LocalPlayer |
3 | local GUI = game.StarterGui.ScreenGui.TextLabel |
4 |
5 | player.PlayerAdded:Connect( function () |
6 | GUI.Text = plr |
7 | 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.
You can get the localplayers name using plr.Name
. Here's an example:
1 | local player = game:GetService( "Players" ) |
2 | local plr = player.LocalPlayer |
3 | local GUI = game.StarterGui.ScreenGui.TextLabel |
4 |
5 | player.PlayerAdded:Connect( function () |
6 | GUI.Text = plr.Name -- Name get's the local players name, that simple |
7 | end ) |
Really simple, good luck with your game!
Put a LocalScript inside of the TextLabel and write this.
1 | 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.
1 | game.Players.PLAYER_NAME_HERE.PlayerGui.ScreenGui.Frame.TextLabel.Text |
Try changing the StarterGui to PlayerGui
1 | local player = game:GetService( "Players" ) |
2 | local plr = player.LocalPlayer |
3 | local GUI = game.PlayerGui.ScreenGui.TextLabel |
4 |
5 | player.PlayerAdded:Connect( function () |
6 | GUI.Text = plr |
7 | end ) |