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

If two player's values are true then..?

Asked by
iFlusters 355 Moderation Voter
8 years ago

I'm having trouble and I have tried multiple types of loops but nothing seems to work, basically I am trying to have a

while true do

-- if 2 players have 'CanPlay' set to true then
-- continue code.

which runs through the players and searches to see if their value "CanPlay" boolvalue is set to true. I know this sounds like a request, but it's not.. and I tried! Please leave help if you can!

My attempts:

if game.Players.NumPlayers >= PlayerNumber and game.Players.NumPlayers.CanPlay == true then then -- Wasn't sure..

-- Tried using loops, the while true do loop is the entire game I have setup.

while true do

if game.Players.NumPlayers >= PlayerNumber then
    for i, v in pairs(game.Players:GetPlayers()) do
        if v.CanPlay.Value == true then
            -- Not sure how to continue.
        end
    end

-- Code
else
end
0
Could you put in one of your more full attempts and then we may show you where it went wrong? NullSenseStudio 342 — 8y
0
Sure iFlusters 355 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

First off, I'd split this into two functions, one to check if there are enough players with CanPlay set to true, and another to loop until the first function returns true.

function enoughPlayers()
end

function waitUntilEnoughPlayers()
    while not enoughPlayers() do wait() end
end

Okay, now to make the enoughPlayers function work. You're off to a good start with looping through each player and checking who has CanPlay set to true. Next I'd make a number variable count up for each player that has CanPlay set to true.

function enoughPlayers()
    local playing = 0
    for i, v in pairs(game.Players:GetPlayers()) do
        local CanPlay = v:FindFirstChild("CanPlay") -- let's be safe and check if the CanPlay BooleanValue exists first aswell
        if CanPlay and CanPlay.Value then
            playing = playing+1
        end
    end
    return playing >= 2 -- this makes the function return true if the playing variable is greater than or equal to 2, otherwise it will return false
end
0
Would I put both funcions inside of the while true do loop or ?? iFlusters 355 — 8y
0
If that while loop is used to handle when a round is being played then you'd need to call the waitUntilEnoughPlayers function before the round part of the loop. NullSenseStudio 342 — 8y
Ad

Answer this question