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

How to iterate through player values?

Asked by 7 years ago
Edited 7 years ago

Im trying to make a function where it checks to see if All the playing values in all players are finished so it can stop a for loop. However, the function is ignored.

Function-

function Finess()
    for i, v in pairs(game.Players:GetChildren()) do
        if v.PlayerValues.Playing.Value == false then
            return 
        end
end
end
for i = 120,1,-1 do
        Status.Value = i
        Finess()
        wait(1)
    end

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I would 1st recommend that you make a table with the values in to make is easier to access.

Your function did not return any value so you will never know when all of the players have finished.

local valList = {}

for I,v in pairs(game.Players:GetChildren())  do
    table.insert(valList, v.PlayerValues.Playing) -- add the reference to our table
end

-- check all players
function Finess()
    for I,v in pairs(valList ) do -- loop using our list
        if not v.Value then -- when we find the 1st player who has not finished return false as we don't need to day anything else
            return false
        end
    end

    return true -- all players finished
end

for i = 120,1,-1 do
    Status.Value = I
    if Finess() then
        -- all players have finished
        -- break
    end
    wait(1)
end

hope this helps.

0
It breaks when all values are true but how would i make it break when all values are false? User#13357 0 — 7y
0
Change line 11 to true, 15 to false? Then change how you want the logic to work on line 20 User#5423 17 — 7y
Ad

Answer this question