Changing a TextLabel via script

I know this is a rookie mistake but until today I thought Gui text was changed via the StarterGui on the explorer. How do I modify a TextLabel’s text property (ScreenGui) to change in every player’s screen?

P.S. Other topics did not really help

1 Like

the for _, player bit will get each player that is in game.Players

1 Like

I will try it out and give feedback when done.

You can do it by looping through players:

local Players = game:GetService("Players")

for _,player in pairs(Players:GetPlayers()) do
player.PlayerGui.ScreenGui.TextLabel.Text = "NewText"

Or with remote events:



local ReplicatedStorage = game:GetService("ReplicatedStorage")


Localscript in the text you can change this in any way you want:

 script.Parent.Text = text

The way I would go about doing this is using an event. It’s not very efficient to change player’s text through a loop every time, it’d be better if you just used FireAllClients

An example would be:

-- Server script
local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') -- Name of your event here, located wherever you want (I put it in ReplicatedStorage)

event:FireAllClients('A message')
-- Client script, in the TextLabel
local event = game.ReplicatedStorage:WaitForChild('RemoteEvent') 
local text = script.Parent -- Location of TextLabel

    text.Text = msg

Thanks for helping out! Here is a cookie! :cookie:

1 Like

Be careful with remote events though since they are exploitable with executors.

1 Like

the OP is only changing the text it wouldn’t be a problem since the text can be changed anyways.