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

Wait For 2 Players script, Adjustments needeed. Any help?

Asked by 8 years ago

My script works great actually :D. It waits till there is atleast 2 players in the server. My game has 4 different teams for 4 different reasons. The 2 that matter in this script are 'Medium stone grey' and 'Institutional white' When your on the institutional white team, you are either in the menu or in the tutorial and the game doesn't affect you. When you are on the Medium stone grey team you are in the lobby and ready to play. I am wanting this script to wait for atleast 2 players on the Medium stone grey team and not 2 players in the server.

Here is my script:

while true do 
wait(2)
if game.Players.NumPlayers < 2 then
    game.Workspace.Message:Remove()
    local h = Instance.new("Hint")
h.Parent = game.Workspace
h.Text = "Need Atleast 2 Players to Play"
elseif game.Players.NumPlayers > 0 then
    game.Workspace.Message:Remove()
    game.ServerStorage.LobbyTimer:Clone().Parent = game.Workspace
    wait(62)

Yes instead of using a repeat wait I used while true do, which needs to stay there. I have the script removing a hint and re-making it into workspace. Which it just cycles and adds a hint then removes it over and over. Which could be not the best way to do it. If you do want to add a reapeat wait feel free to do so, However leave the while true do there for other purposes.

EDIT: I used your script and edited to my liking (So it works the way I need it to)

wait()
while true do 

local NumPlayers = 0  

for _, Player in pairs(game.Players:GetPlayers()) do 

if Player.TeamColor == BrickColor.new('Medium stone grey') then
    wait()  
        NumPlayers = NumPlayers + 1  
    end  
if NumPlayers <  2  then
    wait(.5)
        game.Workspace.Message:Remove()  
            local GameHint = Instance.new("Hint") 
                GameHint.Text = "Need Atleast 2 Players to Play"  
                    GameHint.Parent = game.Workspace  
elseif NumPlayers >  0  then
        wait(.5)
            game.Workspace.Message:Remove()
                game.ServerStorage.LobbyTimer:Clone().Parent = game.Workspace 
                    wait(62)

after the wait 62 other things in the script happen, but however it is too much script to enter into this :p

0
You can replace while true do with while wait(2) do. ISellCows 2 — 8y

1 answer

Log in to vote
0
Answered by
Kurieita 125
8 years ago

So you want it to wait until two players are on a certain team?

You need to do a 'for' loop and count the players on the team

while true do
local NumPlayers = 0

for _, Player in pairs(Game.Players:GetPlayers()) do
if Player.TeamColor == BrickColor.new('Medium stone grey') then 
NumPlayers = NumPlayers + 1
end
end

if NumPlayers <  2  then
local GameHint = Instance.new("Hint")
GameHint.Parent = Workspace
GameHint.Text = "Need Atleast 2 Players to Play"
Game.Players.PlayerAdded:wait()
else 
print("two players are in")
end


Please upvote :)

0
Nice script, but next time you should space out your code. =P ISellCows 2 — 8y
0
Sorry was teting things, i will check it out and see if it works CarterTheHippo 120 — 8y
Ad

Answer this question