How to loop though objects?

Hello,

So I need it so that when a button is clicked it will go through a folder and if the value = the player name it will then do something. I tried this script but seems not to work and I can’t think of any other way I could do this really. By the way all of the objects inside the folder are diffrent not the same

Current server script:

RoomSignout.OnServerEvent:Connect(function(plr, plrUnknow)
	local playerknown = game.Players:FindFirstChild(plrUnknow)
	
	if playerknown then
		print("Vaild user")
		
		for i, v in pairs(game.ServerStorage.ClaimedRooms:FindFirstChild()) do
			if v.Value == plrUnknow then
				print("Playerbookedout")
			else
				print("User is not booked in yet.")
			end
		end
	else
		plr.PlayerGui.ScreenGui.SignOutSystem.Book.Text = "INVAILD USERNAME"
		
		wait(3)
		
		plr.PlayerGui.ScreenGui:Destroy()
	end
end)
1 Like

You used game.ServerStorage.ClaimedRooms:FindFirstChild() which isnt the right way to go
change that with game.ServerStorage.ClaimedRooms:GetChildren()

1 Like

to do a loop you can do

 while true do
 wait()
 end

I don’t want to loop though. I know how to loop if I wanted to lol.

You didn’t understand his question.

That’s not looping through objects, though.

It would be

for i, v in pairs(SomeObject:GetChildren()) do

end
2 Likes

Thanks I completely forgot about the get children.

1 Like

Just think of it as if you’re converting it to a table and then looping through it, that’s whats happening what you use :GetChildren()

No man, you’re completely wrong plus it already worked for him.
You need :GetChildren() @Talls_Smols not FindFirstChild() :laughing:

Wish I could’ve helped you, but yes

for _, v in pairs(AnyObjectWithChildren:GetChildren()) do
     if v.Name == “Whatever” then
          print(“Ayo a child exists”)
     end
end