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

Code refuses to change the text of a label? (No Errors)

Asked by 4 years ago
--> Functions
ChangeTitle = function(newTitle)
    for i,v in pairs(game.Players:GetChildren()) do
        local toChange = v.PlayerGui:WaitForChild("GameGUI").Title
        toChange.Text = newTitle
    end
end
--> Main Game Code
if #CurrentPlayers >= 2 then
    print("More.")
    ChangeTitle("Round starting in 30 seconds!")
elseif #CurrentPlayers < 2 then
    print("Less.")
    ChangeTitle("Waiting for more players!")
end

Before this, I had an event in Rep where I would call upon from a ServerScript. It was defined in a local-script to take the parameter given upon being called by the ServerScript and to use that to replace the text of the TextLabel.

I'm not understanding what i'm doing wrong here, it seems so simple. But, I have no errors in the console..?

It just won't change the text of the TextLabel.

0
Fixed by adding : repeat wait() until game.Players.NumPlayers>0 before calling upon the function. It was trying to call upon it without a player in the game. SevenDevelopment 2 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

First of all, are you using a local script?

Secondly, if I am not mistaken, to get the players of the Service players, you can just use :GetPlayers() instead of children.

--> Functions
ChangeTitle = function(newTitle)
    for i,v in pairs(game.Players:GetPlayers()) do
        local toChange = v.PlayerGui:WaitForChild("GameGUI").Title
        toChange.Text = newTitle
    end
end
--> Main Game Code
if #CurrentPlayers >= 2 then
    print("More.")
    ChangeTitle("Round starting in 30 seconds!")
elseif #CurrentPlayers < 2 then
    print("Less.")
    ChangeTitle("Waiting for more players!")
end

Also, make sure you are looking at output for errors.

0
He did check the output. Read the question. DeceptiveCaster 3761 — 4y
0
Accidentally liked the comment, not sure how to revoke a like goddangit. TheLlamaAlpaca 29 — 4y
0
You need to change the GU via a local gui, not a server script. Syntheix 7 — 4y
Ad

Answer this question