Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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
Ad

Answer this question