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

What did I do wrong?

Asked by 9 years ago

When there is 1 player the message pops up but when the other player comes it doesn't go away

if game.Players.NumPlayers <= 1 then
 Instance.new("Message", Workspace)
    wait(0.1)
    game.Workspace.Message.Text = "This game needs at least 2 players to start!"
    game.Workspace.Mainscript.Disabled = true
else
    game.Workspace.Message.Text = "Game starting!"
    wait(5)
    game.Workspace.Message.Text = ""
    wait(1)
    game.Worksapce.Mainscript.Disabled = false


end


0
Just so you know for your game, atleast is not one word. emite1000 335 — 9y
0
Thanks I fixed it chill22518 145 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

You need to keep looping the script so that it updates the amount of players that are in the game.

local message = --Save this variable for later.

while wait() do
    if game.Workspace:FindFirstChild("Message") == nil then --If the message is not in Workspace, create it.
        message = Instance.new("Message", game.Workspace)
    end
    if game.Players.NumPlayers <= 1 then
        game.Workspace.Message.Text = "This game needs atleast 2 players to start!"
        game.Workspace.Mainscript.Disabled = true
        repeat wait() until game.Players.NumPlayers >= 2 --Wait until there are 2 or more players in game.
    else
        game.Workspace.Message.Text = "Game starting!"
        wait(5)
        game.Workspace.Message.Text = ""
        wait(1)
        game.Worksapce.Mainscript.Disabled = false
        repeat wait() until game.Worksapce.Mainscript.Disabled == true --Waits until the game is over. (Assuming the game ends when the Mainscript is disabled.)
    end
end
0
Thanks! chill22518 145 — 9y
0
But when I tried it it didn't work. chill22518 145 — 9y
0
Posted edits, try that. Spongocardo 1991 — 9y
Ad
Log in to vote
0
Answered by
UgOsMiLy 1074 Moderation Voter
9 years ago
function game()
--do stuff
game()
end
game()

Answer this question