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

How would i use i, v in pairs loops with this???

Asked by 4 years ago

so theres a value in the player

so basically i want to play a function if EVERYONE's value is false. everyone together, not client sided.

i know you have to use the i, v in pairs loop thing but how do i check if EVERYONE's value is false??

0
The normal in pairs loop wouldn't work, as it would check if any of the players value is false and then fire that many times. It would have to be something that either counts the falses or cancels the function when it finds a player whos value is true. Torren_Mr 334 — 4y
0
@Torren_Mr no, i think it really depends on what he wants to use it for, if he only wants to check then the normal in pairs loop will work. crueluu 169 — 4y
0
and he can still use the normal in pairs loop for multiple other scenarios. crueluu 169 — 4y
0
Not really, he made it pretty clear he only wants to play the function if EVERYONE's value is false, so the normal in pairs loop would play it when one players value is false too. I have some ideas but I am currently unable to write a code. Torren_Mr 334 — 4y
View all comments (2 more)
0
hmm... yeah, you're right lol, never thought about that. crueluu 169 — 4y
0
i thought he wanted to do a function on the player if the players value is false. crueluu 169 — 4y

2 answers

Log in to vote
0
Answered by
crueluu 169
4 years ago

Use this, this should work since what it does is go through every current player in the server and check if the value is false, this is not client sided this is a server sided script.

for _,v in pairs(game.Players:GetPlayers()) do
    if v.Value == false then
        --function
    end
end 

0
It wouldn't work, as the script above will go through all the players 1by1, if the players value is false, it will fire the function, it would fire once for every false player. Torren_Mr 334 — 4y
0
you cant be certain, it will work on some/most occasions, if this doesnt work then he'd have to provide further info so we can actually help him. crueluu 169 — 4y
0
I guess it kind of works... Thanks! Toastitions 11 — 4y
0
Yeah, I am sure it will work, just not perfectly, and I think you will be able to work with it and make the solution you want yourself. Torren_Mr 334 — 4y
Ad
Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

Hope this work:

function checkPlayer()
    for i, v in pairs (game.Players:GetPlayers()) do --loop through all players
        if not v.BoolValue.Value then --check is the value inside the player is false or not
            return false -- if it false then return false
        end
    end
    return true -- if every player's value is true then return true
end

-- the rest of the code goes here
0
Yeah, thanks for answering this so I wouldn't have to lol. Great thinking. Torren_Mr 334 — 4y
0
You can use if-then statement to check is the function that i provide, if it true then run your function. Block_manvn 395 — 4y
0
guys im dumb i dont know why he accepted my answer lol, he should accept yours XD. crueluu 169 — 4y
0
Maybe my answer is kinda hard to understand for him but meh Block_manvn 395 — 4y
0
It was probably because he somehow got the previous answer to work and didn't look at your answer. Torren_Mr 334 — 4y

Answer this question