Im making a game and Im trying to make a script so when two people join the game will start, but its not working. Heres the script:
function Countdown() local time = 10 local h = Instance.new("Message",Workspace) for i = time , 1, -1 do wait(1) h.Text = ""..i.." Seconds" end wait(1) h.Text = ""..i.." Seconds" end game.Players.PlayerAdded:connect(function(plr) if NumPlayers == 1 then a = Instance.new("Hint",Workspace) a.Text = "One more player needed!" elseif NumPlayers == 2 then a.Text = "Starting game!" wait(1) game.Workspace.Message:Destroy() Countdown() end end)
I will add a few notes to explain what I did.
function Countdown() time = 10 h = Instance.new("Message",Workspace) for i = time , 1, -1 do wait(1) h.Text = ""..i.." Seconds" end end--You did not need the change text again. The for loop will loop through it, and change the value for you. game.Players.PlayerAdded:connect(function(plr) if game.Players.NumPlayers <= 1 then--Made this less than so it doesn't have to be just 1. h.Text = "One more player needed!" elseif game.Players.NumPlayers >= 2 then--Made this greater than so it doesn't have to be just 2. h.Text = "Starting game!" wait(1) h:Remove()--Instead of destroying it, you can remove it and use it again later. Countdown() end end)
If this doesn't work, comment and tell me what the error message says in the output. I will fix it.