Hello,
So, I am trying to create a searching system for my Datastore that would be used in-game similar to Audio Visualizer Searching System for Audios except it is my Datastore
Image

The issue is that I don’t know how to create that or I am doing it wrongly
So far, I have done a poor job making a Searching System.
Script
game.ReplicatedStorage.Slide1.SearchEvent.OnServerEvent:Connect(function(plr,case, query, Object)
local switch = Switch()
:case(1, function()
local result = {}
for _, items in pairs(GameDataFolder:GetChildren())do
local Tags = string.split(items.Tags.Value, ".")
for _,tags in pairs(Tags) do
if query == tags then
table.insert(result,#result + 1, tonumber(items.Name))
end
end
end
if #result > 0 then
game.ReplicatedStorage.Slide1.SearchEvent:FireClient(plr, result,Object )
else
game.ReplicatedStorage.Slide1.SearchEvent:FireClient(plr, false, Object)
end
end)
:case(2, function()
print(3)
local result = {}
print("starting")
for _, Tags in pairs(TagsDataFolder:GetChildren())do
for _,subTags in pairs(Tags.SubTagsFolder:GetChildren())do
local SubTags = string.split(subTags.Value, ".")
for _, SubTag in pairs(SubTags)do
if query == subTags.Name or query == SubTag then -- this is for subTagsFolder Inside Tags
print(subTags.Name)
print(SubTag)
print(query)
for _,games in pairs(GameDataFolder:GetChildren())do
local gametags = string.split(games.Tags.Value, ".")
for _,gametag in pairs(gametags)do
if gametag == subTags.Name or gametag == Tags.Name then
print("found: ".. games.Name)
break
end
end
end
end
end
end
print(2)
local synonyms = string.split(Tags.Value, ".") -- This is for TagsDataFolder
table.insert(result, #result +1, true)
for _,games in pairs(GameDataFolder:GetChildren())do
for _, synonym in pairs(synonyms)do
if query == Tags.Name or query == synonym then
local gametags = string.split(games.Tags.Value, ".")
for _,gametag in pairs(gametags)do
if gametag == Tags.Name then
print(unpack(result))
for _,results in pairs(result)do
if tonumber(games.Name) ~= results then
table.insert(result, #result +1, tonumber(games.Name))
print(results)
end
end
end
end
end
end
end
end
print("finished")
end)
switch(case)
end)
Firstly, Switch() is just syntax sugar as a Switch Statement. Secondly, please ignore case 1 that isn’t my problem here. Finally, My concept here is that a query would be received from a client via RemoteEvent and with that query, it would loop through the datastore, which is converted in a form of Folders and Values that is parented to ServerStorage, until the query is equal to Tags.Name or its Value in TagsDataFolder then it would find all items in GameDataFolder that has Tags equal to the Tags found in TagsDataFolder.
And I am also gonna implement this for SubTagsFolder which a folder inside tags that are in TagsDataFolder
The Script is the aftermath of me print debugging so I apologize if it is messy or unclear. But I found out is that result is always duplicated in three times or nine times which I assume it is from i,v looping.
Output
3
starting
2 (x3)
true true true
true (x3)
true true true 286090429 286090429 286090429
true (x3)
true true true 286090429 286090429 286090429 286090429 286090429 286090429
true (x3)
true true true 286090429 286090429 286090429 286090429 286090429 286090429 286090429 286090429 286090429
true (x3)
286090429 (x9)
true true true 286090429 286090429 286090429 286090429 286090429 286090429 286090429 286090429 286090429 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879
true (x3)
286090429 (x9)
true true true 286090429 286090429 286090429 286090429 286090429 286090429 286090429 286090429 286090429 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879 3233893879
true (x3)
286090429 (x9)
finished
Any help or suggestions would Useful 