Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Auto-generated database not fully working. Any ideas how to fix it?

Asked by 3 years ago


for o, sort in pairs(database:GetChildren()) do print("a"..tostring(o)) for a, val in pairs(script:GetChildren()) do print("b"..tostring(a)) for i, v in pairs(database[sort.Name]:GetChildren()) do print(finishedGames) if not table.find(finishedGames, val.Value) then print("c"..tostring(i)) local data = getData(val.Value) v.Description.Value = data.Description v.Online.Value = data.OnlineCount v.GameID.Value = val.Value v.Likes.Value = data.TotalUpVotes v.GameName.Value = data.Name print(v.GameName.Value) v.Dislikes.Value = data.TotalDownVotes v.Visits.Value = data.VisitedCount v.Favorites.Value = data.FavoritedCount table.insert(finishedGames, i, val.Value) end end end end

So basically I'm using a database for my game. And I want that database to be generated automatically. So from what I've figured out, the values are set for only one "v" in this instance instead of all "v"s. If you need further explanation feel free to ask. I figured out that it's only looping for one singular instance instead of all of them.

1 answer

Log in to vote
0
Answered by 3 years ago

This seemed to work:

game.ReplicatedStorage.refreshingDatabase.Value = true

repeat wait() until game.ServerStorage.finishedSavingLoading.Value == true

local module         = require(game.ServerScriptService.ModuleScripts.placeStats.ModuleScript)
local HTTP           = game:GetService('HttpService')
local database       = game.ServerStorage.Database
local refreshingData = game.ReplicatedStorage.refreshingDatabase

-- tables

local genres        = {"All", "Building", "Horror", "Town and City", "Military", "Comedy", "Medieval", "Adventure", "Sci-Fi", "Naval", "FPS", "RPG", "Sports", "Fighting", "Western", "Skatepark"}
local usedGenres    = {}
local finishedGames = {}

local genreTables = {
All         = {},
Building    = {},
Horror      = {},
TownAndCity = {},
Military    = {},
Comedy      = {},
Medieval    = {},
Adventure   = {},
SciFi       = {},
Naval       = {},
FPS         = {},
RPG         = {},
Sports      = {},
Fighting    = {},
Western     = {},
Skatepark   = {}
}

local function removeSymbols(str, symbol)

    return str:gsub(symbol,"")

end

local function makeGameData(sort, gameSerial)

    local gameFolder = Instance.new("Folder", database:FindFirstChild(sort.Name))
    gameFolder.Name  = tostring(gameSerial)

    local clicks = Instance.new("IntValue", gameFolder)
    clicks.Name  = "Clicks"

    local description = Instance.new("StringValue", gameFolder)
    description.Name  = "Description"

    local online = Instance.new("IntValue", gameFolder)
    online.Name  = "Online"

    local gameID = Instance.new("IntValue", gameFolder)
    gameID.Name  = "GameID"

    local likes  = Instance.new("IntValue", gameFolder)
    likes.Name   = "Likes"

    local gameName = Instance.new("StringValue", gameFolder)
    gameName.Name  = "GameName"

    local dislikes = Instance.new("IntValue", gameFolder)
    dislikes.Name  = "Dislikes"

    local maxClicks = Instance.new("IntValue", gameFolder)
    maxClicks.Name  = "MaxClicks"

    local visits = Instance.new("IntValue", gameFolder)
    visits.Name  = "Visits"

    local favourites = Instance.new("IntValue", gameFolder)
    favourites.Name  = "Favorites"

    local devsChoice = Instance.new("BoolValue", gameFolder)
    devsChoice.Name  = "devsChoice"

end

local function getData(placeId)

    local stats = {}
    local success, err = pcall(function()
        local API = HTTP:JSONDecode(HTTP:GetAsync('https://www.rprxy.xyz/places/api-get-details?assetId=' .. placeId, true))
        stats = {
            OnlineCount    = API.OnlineCount;
            VisitedCount   = API.VisitedCount;
            Name           = API.Name;
            Created        = API.Created;
            Updated        = API.Updated;
            Description    = API.Description;
            FavoritedCount = API.FavoritedCount;
            TotalUpVotes   = API.TotalUpVotes;
            TotalDownVotes = API.TotalDownVotes;
            AssetGenre     = API.AssetGenre
        }
    end)

    return (err and warn(err)) or stats

end

local function makeGius(player, genre)

    wait(1)

    local playerGui = player.PlayerGui
    local base      = playerGui.Base
    local baseBoard = playerGui.BaseBoard

    local newBase      = base:Clone()
    local newBaseBoard = baseBoard:Clone()

    newBase.Parent                     = playerGui
    newBaseBoard.Parent                = playerGui
    newBaseBoard.Script.Disabled       = false
    newBase.MainFrame.Handler.Disabled = false

    newBase.Name            = genre
    newBase.Info.Type.Value = genre

    newBaseBoard.TypeText.Text = genre
    newBaseBoard.Name          = genre.."Board"

    if baseBoard:FindFirstChild("Script") then

        baseBoard.Script.Disabled = true

    end

    if base.MainFrame:FindFirstChild("Handler") then

        base.MainFrame.Handler.Disabled = true

    end

end

local function makeSorts()

    local counter = 0

    print("EEEEE")

    for i, GameID in pairs(script:GetChildren()) do

        local gameId = GameID.Value

        for i, genre in pairs(genres) do

            print(getData(gameId).AssetGenre)

            if getData(gameId).AssetGenre == genre and not table.find(usedGenres, genre) then

                print("A")

                counter = 1

                table.insert(usedGenres, counter, getData(gameId).AssetGenre)

                local newFolder = Instance.new("Folder", database)
                newFolder.Name  = genre

                print("B")

                for i, player in pairs(game.Players:GetPlayers()) do

                    for i, genre in pairs(usedGenres) do

                        makeGius(player, genre)                     

                    end

                end

                print("CC")

                for i, player in pairs(game.Players:GetPlayers()) do

                    local playerGui =player.PlayerGui
                    local base      = playerGui.Base
                    local baseBoard = playerGui.BaseBoard

                end

                counter = 0

                local modifiedGenre = ""

                if genre:match(" ") then

                    -- contains a space
                    modifiedGenre = removeSymbols(genre, " ")

                elseif genre:match("-") then

                    -- contains a dash
                    modifiedGenre = removeSymbols(genre, "-")

                end

                local genreTable = genreTables[genre]
                table.insert(genreTable, counter, modifiedGenre)

                counter += 1

            end

        end

    end

end

local function sortGames()

    local counter = 0

    --[[for a, sort in pairs(database:GetChildren()) do

        counter = 0

        for e, genreInTable in pairs(genreTables) do

            for i, gameFolder in pairs(genreInTable) do

                counter += 1
                makeGameData(database:FindFirstChild(sort.Name), counter)

            end

        end

    end--]]

    for i, genre in pairs(database:GetChildren()) do

        local counter = 0

        --for e, genreTable in pairs(genreTables[genre.Name]) do

        for e, genreInTable in pairs(genreTables) do

            for i, gameFolder in pairs(genreInTable) do

                counter += 1
                makeGameData(database:FindFirstChild(genre.Name), counter)

            end

        end

        --end

    end

end

local newData        = database:Clone()
newData.Parent       = game.ReplicatedStorage

local function totalSortage()

    print("Started total sortage")

    database                                       :ClearAllChildren()
    game.ReplicatedStorage:WaitForChild("Database"):ClearAllChildren()

    refreshingData.Value = true

    print(1)

    makeSorts()

    print(2)

    sortGames()

    local sorts       = database:GetChildren()
    local games       = script:GetChildren()

    print(3)

    for i, gameID in pairs(script:GetChildren()) do

        local data = getData(gameID.Value)

        for e, folder in pairs(database[data.AssetGenre]:GetChildren()) do

            folder.Description.Value = data.Description
            folder.Online.Value      = data.OnlineCount
            folder.GameID.Value      = gameID.Value
            folder.Likes.Value       = data.TotalUpVotes
            folder.GameName.Value    = data.Name
            folder.Dislikes.Value    = data.TotalDownVotes
            folder.Visits.Value      = data.VisitedCount
            folder.Favorites.Value   = data.FavoritedCount
            folder.Clicks.Value      = gameID.currClicks.Value
            folder.MaxClicks.Value   = gameID.maxClicks.Value
            folder.devsChoice.Value  = gameID.devsChoice.Value

        end

    end

    --[[for i, sort in pairs(sorts) do

        if table.find(usedGenres, sort.Name) then

            for o, gameID in pairs(games) do

                local data = getData(gameID.Value)
                local ID   = gameID.Value

                if sort:FindFirstChild(tostring(o)) then

                    local folder = sort[tostring(o)]

                    folder.Description.Value = data.Description
                    folder.Online.Value      = data.OnlineCount
                    folder.GameID.Value      = ID
                    folder.Likes.Value       = data.TotalUpVotes
                    folder.GameName.Value    = data.Name
                    folder.Dislikes.Value    = data.TotalDownVotes
                    folder.Visits.Value      = data.VisitedCount
                    folder.Favorites.Value   = data.FavoritedCount
                    folder.Clicks.Value      = gameID.currClicks.Value
                    folder.MaxClicks.Value   = gameID.maxClicks.Value
                    folder.devsChoice.Value  = gameID.devsChoice.Value

                end

            end

        end

    end--]]

    refreshingData.Value = false

    game.ReplicatedStorage:WaitForChild("Database"):Destroy()
    local newData2  = database:Clone()
    newData2.Parent = game.ReplicatedStorage

    print("Ended total sortage")

end

game.Players.PlayerAdded:Connect(function(player)

    for i, genre in pairs(usedGenres) do

        makeGius(player, genre)

    end 

end)

totalSortage()

print(genreTables)

while wait(30*60) do

    totalSortage()

end

Ad

Answer this question