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:
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
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
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