Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make it so it gets all the players' guis and changes the text?

How do I make it so it gets all the players' guis and changes the text?

local players = game.Players:GetChildren()

while true do
	players.PlayerGui.ScreenGui.TextLabel.Text = "Test"
	wait(4)
	players.PlayerGui.ScreenGui.TextLabel.Text = "Test2"
	wait(4)
end

Thanks!

1 answer

✓ Accepted answer

Simple! But, there's two ways to do it! One way is easier to change for further changes, the other is just adjusting your above code.

Way 1) Adjusting Your Code

function ChangeText(txt)
	for _,player in pairs(game.Players:GetPlayers()) do
		pcall(function() -- "try to do the following", i.e. the next line doesn't error if something goes wrong, e.g. an item hasn't loaded yet
			player.PlayerGui.ScreenGui.TextLabel.Text = txt
		end)
	end
end

while true do
    ChangeText("Test")
    wait(4)
   ChangeTest("Test2")
    wait(4)
end

Way 2) Efficiency!

You might've noticed that on many games, including faves like The Mad Murderer, the text usually at the top of the screen displays the status of the game, which changes text just like you're intending to do. You could do the first way a lot if you wanted, but the repetition would surely knacker you out!

Here's what people like loleris do: create a StringValue in ReplicatedStorage called "GameStatus" or something. Set its value to something generic, e.g. "Loading Game..." or just blank (this part isn't important). Then, in the textlabel, add a script:

local status = game.ReplicatedStorage:WaitForChild("STRINGVALUE_NAME") -- replace "STRINGVALUE_NAME" to the stringvalue's name
function UpdateText()
	script.Parent.Text = status.Value
end
status.Changed:connect(UpdateText)
UpdateText()

and in that ServerScriptService script:

local status = game.ReplicatedStorage:WaitForChild("STRINGVALUE_NAME") -- replace "STRINGVALUE_NAME" to the stringvalue's name
while true do
    status.Value = "Test"
    wait(4)
   status.Value = "Test2"
    wait(4)
end

Now, any script in the place can change the text globally- not that one script! This makes it easier and more dynamic, as the changing of the text depends on the client rather than the server!

Hope this has helped! Cheers :) CD

3 comments

0

Wow you sound so pro, thanks!

0

Way 2) Thought me a lot. Thanks a lot :)

0

You're welcome! Happy to help ;)

This discussion is preserved as it was. New answers, comments, and votes are closed.