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

What Is Wrong With My NumPlayer?

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 :'(

2 comments

0

I edited my answer to reflect your other question.

0

Thanks

1 answer

✓ Accepted answer
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)

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