How to change TextLabel Through Server Script in ServerScriptService?

I wanted to change the Text in my ScreenGui textlabel but there seem to be impossible based on the result I tried to find in this platform and google.

I tested this code which was said to supposedly work. I’ve check many times for misspelt in the code or the name of the textlabel, everything is fine. So I don’t know why its not working…

This target only a single user
game.Players.Playername.PlayerGui.ScreenGui.Textlabel.Text = "Hello World"

This loop thru every players

for _,v in pairs(game.Players:GetChildren()) do
	    v.PlayerGui.ScreenGui.TextLabel.Text = "Hello World"
		end
1 Like

Are they any errors in output?

1 Like

the end is wrongly indented dk if that was just a mistake copying it

for _,v in pairs(game.Players:GetChildren()) do
    v.PlayerGui.ScreenGui.TextLabel.Text = "Hello World"
end
1 Like

Sadly nothing shows up on the Output

yea wrote it like that, still nothing

Try this maybe

for i, Player in pairs(game:GetService'Players':GetPlayers()) do
	Player:WaitForChild'PlayerGui':WaitForChild'ScreenGui':WaitForChild'TextLabel'.Text = "Hello World"
end
1 Like

If you change a textlabel by a local script it will overwrite the existing changes a script has made

make sure you have no local scripts changing the text

1 Like

You can’t do that access client with server script. try to use remote events

1 Like

Copied the exact thing, no changes

yea, no local script under made ScreenGui

You can as long as the client makes no changes

1 Like

Are you sure the textlabel is inside of screengui and is script.Disabled set to false?

1 Like

Are there any warning messages in the output after you wait for like 10 seconds?

1 Like

Its working fine for me, whats the problem?
Btw, when the serverscript starts, the player is not in server yet, the character delays time to spawn, so try adding a wait(10) just for test. You are maybe trying to change a text that doesnt exist yet in the client, cause theres no client in server.

wait(10)
print("change now")
for _,v in pairs(game.Players:GetChildren()) do
	v.PlayerGui.ScreenGui.TextLabel.Text = "Hello World"
end
1 Like

Oh yeah I get what you’re saying
maybe try and connect it to a PlayerAdded event as well instead of loops
Because of there is nothing inside a table and a loop tries to loop through it I’m pretty sure the script just ignores that code

2 Likes

It would error if that happened though, no?

1 Like

No it would just ignore the code, I’m pretty sure cause this happened when I was making a spectate system

2 Likes

I think that theres no error, because its iterating into the Clientes in server, and because there is no client when the code is running, then it never does the
v.PlayerGui.ScreenGui.TextLabel.Text = "Hello World"

When I tested the code with the wait(10) everything works fine

EDIT: And @legs_v is totally right. Managing this on events when the player join is the best idea. The wait(10) was just for testing

2 Likes

Weird, I copied the same exact code. Not even print("change now") shows up…

Probably cause you have to wait 10 seconds for it to print?

1 Like