How do I check the values in a folder?

Hello! I wanted to see if I can make a local script that checks the values in a folder to see if one of them has the player’s username as the value. Here are my StringValues in my folder in ReplicatedStorage:

Screenshot 2023-08-30 162315

So far I only tried this:

local user = game.Players.LocalPlayer.Name
for _, room in pairs(game.ReplicatedStorage.Owners:GetChildren()) do
		
    if room.Value == user then
        --player already owns a room
  end
end)

I don’t know what else to do so any help is appreciated. Also I hope you understood my explanation

does the code give you any errors?

try to remove the ) at the end

There seems to be nothing wrong with this script except the error @local_meEgual1 said above

What you can do is stop the loop as soon as the owner is found, and you can do this like this:

local user = game.Players.LocalPlayer.Name
local foundOwner = nil
for _, room in pairs(game.ReplicatedStorage.Owners:GetChildren()) do
    if room.Value == user then
        foundOwner = user
        break
   end
end
if foundOwner ~= nil then --should be the player's name
   --player already owns a room
end
1 Like

Sometimes you will find issues with things like this, make sure the variable “user” you are using to compare to the room.value is the same type, use tostring to tonumer to guarantee this

Thank you so much, this helped me out a ton!!

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