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

What Is Wrong With My NumPlayer?

Asked by 10 years ago
if Game.Players.NumPlayers == 4 then
wait(3)
print("Working!")

script.Parent.Text = "8"
Game.Workspace.Tick:Play()
wait(1)
script.Parent.Text = "7"
Game.Workspace.Tick:Play()
wait(1)
script.Parent.Text = "6"
Game.Workspace.Tick:Play()
wait(1)
script.Parent.Text = "5"
Game.Workspace.Tick:Play()
wait(1)
script.Parent.Text = "4"
Game.Workspace.Tick:Play()
wait(1)
script.Parent.Text = "3"
Game.Workspace.Tick:Play()
wait(1)
script.Parent.Text = "2"
Game.Workspace.Tick:Play()
wait(1)
script.Parent.Text = "1"
Game.Workspace.Tick:Play()
wait(1)
end

As you can see, I am making a script when there are four players in the server. Now, this script is under a SurfaceGui in a Part. The word 'Tick' is the sound that will be playing in my game. When I played this script it didn't work. Why's that?

Someone halp meh please :'(

0
I edited my answer to reflect your other question. Articulating 1335 — 10y
0
Thanks DesignerDavid 0 — 10y

1 answer

Log in to vote
1
Answered by 10 years ago
function waitForPlayers(minimum)
    repeat 
        Game.Players.PlayerAdded:wait() --Wait for another Player to be added
    until Game.Players.NumPlayers >= minimum --Stop waiting if there are enough players.
end

waitForPlayers(4)
for i = 8,1,-1 do
    script.Parent.Text = tostring(i)
    Game.Workspace.Tick:Play()
    wait(1)
end

Game.Players.PlayerRemoving:connect(function()
    wait()
    if Game.Players.NumPlayers < 3 then
        script.Parent.Text = ""
        --Reverse anything else that you might have done.
        Spawn(function() --I believe that a thread created with Spawn will continue even if the original script is disabled. Please comment if not.
            script.Disabled = true
            script.Disabled = false
        end)
    end
end)
Ad

Answer this question