Ello. I wasn’t really sure how to title this, so I do apologize if it’s kind of weird. I’ll try to explain this simply…
In this script, I’m going through a collection on a external database. I’m trying to check for if there is a entry already made with the same players userId. But, because of the else function, it just keeps making a new one for every entry that doesn’t have the players userId.
Is there a way I can just make it so after it goes through all entries, if there’s no entry with the players userId, it will do this or whatnot?
local function OnPlayerAdded(plr)
print("plrAdded")
local UserTable = DataStoreService:GetDataStore("UserTable") -- I was gonna use this to like keep track of what entries ive gone through?
for i=1, #Collection do
local DataPiece = Collection[i]
print("plrDetect")
if DataPiece.UserId == plr.UserId then
print("HasUser!")
script.playerID.Value = DataPiece["_id"]
print("ID: " .. script.playerID.Value)
print("DataPiece: " .. DataPiece["_id"])
game.ReplicatedStorage.GotID:FireClient(plr)
print("SetValue!")
else
print("Not Found! Adding!")
UserTable:SetAsync("PlayerDetection_" .. plr.UserId , true)
API:AddDocument("whitelistedusers", {
["Username"] = plr.Name,
["UserId"] = plr.UserId
})
end
end
end
P.S. I just tried doing a table, but unfortunately it won’t work, or atleast not the way I’m trying. The database unique id’s are both letters & numbers, so not sure how I would find those through table.find. I’m not sure how dictionaries work either, or if they’d work in this circumstance. Any ideas? Thank you!
P.S.S I just tried a datastore as well, but not sure how I would go about doing that… Any ideas help!