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

What did I do wrong?

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


2 comments

0

Just so you know for your game, atleast is not one word.

0

Thanks I fixed it

2 answers

✓ Accepted answer

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

3 comments

0

Thanks!

0

But when I tried it it didn't work.

0

Posted edits, try that.

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