How to define all players when changing GUI text

I want to make a line of text change for all players on a GUI.
What would I use here:

game.Players.(something).PlayerGui.....
2 Likes

Just make a loop

 for _, player in pairs(game.Players:GetChildren()) do
     player.PlayerGui...
end
2 Likes

You have to get all the players with :GetChildren() function and then for each one change PlayerGui text.

for i,v in pairs(game:GetService("Players"):GetChildren()) do
    v.PlayerGui:FindFirstChild("ScreenGUIName"):FindFirstChild("TextName").Text = "Changed string" -- Locate your own text and also a change
end
2 Likes

Hi!
This works , however it doesn’t update for new players who join
Is there any way I can get it to do that or not?
My full script is:


local AutoApps = game.ServerScriptService.AutoCommends

script.Parent.MouseButton1Click:Connect(function()
	wait(0.4)
	if AutoApps.Disabled ==  true then
		for i,v in pairs(game:GetService("Players"):GetChildren()) do
			v.PlayerGui:FindFirstChild("GUI"):FindFirstChild("UI"):FindFirstChild("Main"):FindFirstChild("AutoAppsStatus").Text = "Off"
		end
		
	elseif AutoApps.Disabled == false then
		for i,v in pairs(game:GetService("Players"):GetChildren()) do
			v.PlayerGui:FindFirstChild("GUI"):FindFirstChild("UI"):FindFirstChild("Main"):FindFirstChild("AutoAppsStatus").Text = "On"
		end
		
	end
end)
1 Like

Use a remote event instead and fire all clients.

1 Like

I recommend that you use a public string value in ReplicatedStorage and change this value with a script. Then you can use a local script parented to the text you’d like to change the text. Like this:

local ValueChanged = game:GetService("ReplicatedStorage"):WaitForChild("StringValueName")   

script.Parent.Text = ValueChanged.Value
ValueChanged.Changed:Connect(function()
   script.Parent.Text = ValueChanged.Value
end)
1 Like