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

How to make this?

So basically I was wondering how to make a function that would check to see if all the players IntValue is set to 0 or if one person's IntValue is set to 1.

I know this may be useless, but I think it might help:

function playersCurrentlyPlaying()
	for loopTime, loopPlayers in ipairs (game.Players:GetChildren()) do
		if loopPlayers.playValue.Value == 1 then 
			return true
		else
			return false
		end
	end
end

I would appreciate it if you showed me how to do it, thanks!

4 comments

0

Does that work?

0

you need to use a flag and return it at the end of the loop

0

This doesn't really help at all, could you possibly explain it?

0

added a description

1 answer

you need to add a flag. A flag in case you didn't know is a variable that is used to detect a change or look for an outlier in a list this case being all of the players. So we can use it to see if one player isn't playing and if so change our flag variable accordingly.

function playersCurrentlyPlaying()	
    	local flag = 0

    	for loopTime, loopPlayers in ipairs (game.Players:GetChildren()) do
        	if loopPlayers.playValue.Value == 0 then 
			-- the player on this iteration isn't playing so we change the flag
           		flag = 1
        	end
   	end

    	if flag == 0 then 
 		-- every player is playing 
		return true 
    	else
		-- one or more players isn't playing
		return false
    	end
end

this will check to see if all the players are playing

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