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"
end

Or with remote events:

image

Serverscript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

ReplicatedStorage.ChangeText:FireAllClients("Text")

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

ReplicatedStorage.ChangeText.OnServerEvent:Connect(function(text)
 script.Parent.Text = text
end)
4 Likes

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

event.OnClientEvent:Connect(function(msg)
    text.Text = msg
end)

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.