Make TextLabel's Text equal to LocalPlayer's Name From a Script

Ok so I’m going to make this short. I am making a keycard that will change a TextLabel’s Text to be the name of the Local Player. Obviously to replicate it across the server, I need to make it a Script and not a LocalScript. The current code I have is as follows:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	game.Players.player.Backpack["Level [3]"].text.sg1.TextLabel.Text = game.Players.player.Name
end)

No errors or warnings occur when running the script, but the Text does not change. This solution seems obvious, but I can’t find the answer. Thank you for your understanding.

It seems you’re attempting to find player as a child from Players however player is an instance.
Try player.Backpack["Level [3]"].text.sg1.TextLabel.Text = player.Name

Also, if you’re looking for this to happen all the time (when the player dies) you need to use a CharacterAdded event and put the code under that.

1 Like

Ok, so I’ve updated the script to look like this,

local Players = game:GetService("Players")

local function onCharacterAdded(player)
    player.Backpack["Level [3]"].text.sg1.TextLabel.Text = player.Name
end

but when I run that it still won’t change the text.

Is “Level [3]” a ScreenGui or BillboardGui/SurfaceGui?

You have to run the function all you have to do is,

local Players = game:GetService("Players")

local function onCharacterAdded(player)
    player.Backpack["Level [3]"].text.sg1.TextLabel.Text = player.Name
end
Players.PlayerAdded:Connect(onCharacterAdded)

Still didn’t work after this script.

It is a SurfaceGui @SovereignObesity

Any errors in your output? and where is that script located?

No errors in the output, Script located in the TextLabel I’m trying to change.

if its a script change it to a local one and just do

local plr = game.Players.LocalPlayer 
plr.Backpack["Level [3]"].text.sg1.TextLabel.Text = plr.Name

also make sure your script is not disabled :sweat:

He wants it to show for every other user

Server scripts can’t modify gui’s, If he wants to do so he must fire a remote event to all clients in order for it to be visible for everyone.

They can modify SurfaceGuis as far as I’m aware.

Even if your making the script go into the player’s GUI?

Do something like this in the client

function Main(player)
 player.Backpack["Level [3]"].text.sg1.TextLabel.Text = player.Name
end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
Main(player)
end)
end)

for _, v in next, game.Players:GetPlayers() do
Main(v)
end

Last line it uses a LocalPlayer and won’t work.

Do it in a local script.
It uses PlayerAdded and CharacterAdded so it’ll change for all players when they join

I did the script, it worked and replicated, but when the player resets it won’t replicate server wide, should I use character added instead?

Yeah I only just included it in. Check my edit

I don’t see an edit, where is it?