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
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
the for _, player bit will get each player that is in game.Players
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:
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)
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!
Be careful with remote events though since they are exploitable with executors.
the OP is only changing the text it wouldn’t be a problem since the text can be changed anyways.