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

I am trying to save a table using datastore but don't know how to?

Asked by 2 years ago

Below is my current script and also keep in mind I have no idea what the hell im doing.

local ds = game:GetService("DataStoreService")
local dss = ds:GetDataStore("PhrogTable")
local PhrogFolder = game.Workspace.Phrogs:GetChildren()
local PhrogTable = {}
local PhrogsTable = {
    "GhostL0" == false;
    "KingL0" == false;
    "OgreL0" == false;
    "GrassL1" == false;
    "KingL1" == false;
    "WizardL1" == false;
    "RockHousL2" == false;
    "RockL2" == false;
    "LavaL2" == false;
    "HermitL2" == false;
    "RockBarL2" == false;
    "RockBarteL2" == false;
}

game.Players.PlayerAdded:Connect(function(player)
    local Collected = Instance.new("Folder",player)
    Collected.Name = "Collected"

    local Success, Error = pcall(function()
        dss:GetAsync(player.UserId.."-PhrogTable")
    end)

    if Success then
        PhrogsTable = dss
    end

    for i,v in pairs(Collected) do
        table.insert(PhrogTable, v)
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local Success, Error = pcall(function()
        dss:SetAsync(player.UserId.."PhrogTable", PhrogTable)
    end)
end)

Answer this question