For i,v in pairs help!

So today i decided to make a Level Pass Checker, For Example, Checks if player is attempting to join a new level, when another level already started, Im trying to make a Checker, using for i,v in pairs, by checking BoolValues i have saved in the Player Folder. When a player Starts a Level, The Values turn into true.

for _, GetLevelValues in pairs(ClientLevelFolder:GetChildren()) do
				if GetLevelValues:IsA('BoolValue') then
					-- Compare if CheckValueTrue == true then, Compare with part it touched.
					
					if GetLevelValues.Value == true then
						self.ActiveLevel = GetLevelValues
						
						if self.ActiveLevel.Name == tostring(PortalLevel) then
							print('{Client}: Attempted to Join active level, Passed!')
						else
							print('{Client}: Attempted to Join Different level, Failed!')
						end
					else
						if self.ActiveLevel ~= nil then return end -- If No Active Level Found
						self.FireRemote()
					end
					
		
					
					
					
				end
			end	

from what i understand, The code is detecting the other values in the folder, which are false, which are triggering the, IF Values false behavior. Any workaround this?

4 Likes

I don’t really understand about what you said. Can you explains a little bit more ?

3 Likes

I Explained it perfectly, I said im making a Level Requirements system, Which checks the current active levels from a BoolValue folder i have, The requirement is checking, If another level value is true, and if player is trying to start a new level, when another level is active, Im achieving this by turning the BoolValues true when Client starts level

Example: Player Starts Level. Level1.Value = true
Player Attemps to Join Another Level, Requirements Check this
Example
for i,v in pairs(level) do
if v.Value == true then
if v.Name == LevelTryingToStart then
fire remote
else
dont fire remote
end
end
end

1 Like

Yeah but what’s the problem ? I didn’t understand the problem.

1 Like


Since its for i,v in pairs, is looping through my folder, The False Requirement behavior Also fires, since its also looping through values that are FALSE… Maybe look at the code …

1 Like

FIX
I need a work around the code, Since , its still firing the IF NO ACTIVE LEVEL FOUND Behavior, When level was found, which it isn’t supposed to fire, what i know is, its detecting the False values of the other values of the folder. which is why this is Happening, Need a workaround this.

1 Like

Random question but have you maybe visual checked that the value is being updated and it’s an error associated with that script?

1 Like

I have the values, Manually enabled to test them. So yes, Nothing has to do with that, Again, do you not understand how For i,v in pairs work?, For i,v in pairs, Loops through all the values. Even if i find the True Value, The False Behavior still runs, Because for i,v in pairs has found the false value

1 Like

If you want to break the loop write break and if not so… uh… I don’t know.

1 Like

tried it already 30 chaaaaaaaars

1 Like

I think your issue is that you’re looping through every single level value, why not just reference the single level the player is trying to join?

1 Like

Sounds like you may need a different approach to your functionality here. You shouldn’t rely on a for-loop in particular for this.

If you only want to find the value of a specific Value object, you should make use of the Name property to find the correct value.

Nevermind guys. Fixed it. Did some tweeking and it works now, Soultion was,

if level.value == true then
levelEnabled = level
end

if levelEnabled then
– do Active levels stuff
elseif nil then
– Do No Active level stuff
end

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.