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

What went wrong here?

Asked by 9 years ago
Player = game.Players:GetPlayerFromCharacter()
countPlayers = game.Players.NumPlayers
waitGui = game.Workspace.mainGui.lobbyWait
waitText = waitGui.TextLabel.Text
while countPlayers <= 1 do
    waitText = "testing, testing, 123"
end

The GUI's text does not change.

Please help me resolve this.

Thank you.

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

The problem is that 'countPlayers' will always be the same because you're not defining it inside the loop. So if, initially, 'countPlayers' wasn't less than or equal to one then it will never change.

Also, you cannot change a property from a variable directly. If you set a variable to a property, the variable becomes 'read only'. Set 'waitText' to the TextLabel, not the Text property of it.

And I have no idea what you were doing with the GetPlayerFromCharacter method.

local num = 1
waitText = workspace.mainGui.lobbyWait.TextLabel

while wait() do
    local countPlayers = game.Players.NumPlayers
    if countPlayers <= num then
        waitText.Text = "testing, testing, 123"
    end
end
Ad
Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
9 years ago

3 Things Unintentionally Done With Your Script:

  • Careful with while loops. You will need a "wait()," else Roblox will crash.

  • countPlayers refer to the value of the NumPlayers property, not the property itself.

    • countPlayers will always be the number that it is assigned to, so if the server starts, the initial amount of players in the game is 0.
while game.Players.NumPlayers <= 1 do
    -- Code here
    wait()
end
  • Same case for waitText.
while game.Players.NumPlayers <= 1 do
    waitGui.Textlabel.Text = "testing, testing, 123"
    wait()
end

What's the purpose of the first line? Delete that line out if you're not going to use it. This is for efficiency.

Answer this question