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

How to iterate through player values?

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

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.

2 comments

0

It breaks when all values are true but how would i make it break when all values are false?

0

Change line 11 to true, 15 to false? Then change how you want the logic to work on line 20

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