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

How do you change the text label for everyone in the game?

So I am making a minigame and I want to make the textlabel change the text for everyone to see! Heres the script

SCRIPT!

local RepStore = game:GetService("ReplicatedStorage")
local remote = RepStore:WaitForChild("Remote") --LOCATING THE REMOTE

remote.OnServerEvent:Connect(function()

for i, v in pairs(game.Players:GetChildren()) do
	local pgui = v:WaitForChild("PlayerGui")
		pgui:WaitForChild("MainText").TextLabel.Text = "Not enough players to start!" 
		--Chaning the players textlabel
end
end)

LOCAL SCRIPT

local RepStore = game:GetService("ReplicatedStorage")
local remote = RepStore:WaitForChild("Remote")

remote:FireAllClients() --Firing the client

Thank you!

1 answer

###You are doing it the other way around. The client should be doing the changes, the server firing the remote to the client. Your script would only work in Play Solo, though. The server and client are not separated in this mode. In a real game, the server cannot access the descendants of PlayerGui, unless said descendants were placed by the server. You would instead have the client do all the work and the server would just fire the remote.

local client = game:GetService("Players").LocalPlayer
local RepStore = game:GetService("ReplicatedStorage")
local remote = RepStore.Remote -- LOCATING THE REMOTE

remote.OnClientEvent:Connect(function()
    local pgui = client.PlayerGui
    pgui:WaitForChild("MainText").TextLabel.Text = "Not enough players to start!" 
    --Chaning the players textlabel
end)

###Server:

local RepStore = game:GetService("ReplicatedStorage")
local remote = RepStore.Remote

remote:FireAllClients() --Firing to the clients

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