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

Game player waiting?

Asked by
dreamy67 135
10 years ago

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)
0
Define NumPlayers. NumPlayers = game.Players.NumPlayers Shawnyg 4330 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

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.

0
If it was: game.Players.NumPlayers >= 2 then wouldnt it run everytime someone joins? dreamy67 135 — 10y
Ad

Answer this question