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

Datastore Not Saving all Values?

Asked by 5 years ago
Edited 5 years ago

So I'm working with a data store in a racing game. The datastore is suppose to save the players money and miles driven and their rank. Also in a folder thats not leaderstats it's suppose to save cars that they buy. The script has been working fine for months but now all of the sudden it stopped saving everything in leaderstats, so the money{Rowg Coins} miles driven and rank. But it still saves the cars. Any suggestions would be greatly appreciated.

local DSS = game:GetService("DataStoreService")
local RepStorage = game:GetService("ReplicatedStorage")

local RedlinePlayerDS = DSS:GetDataStore("RedLineRacing-DS")
local EventTutorial = RepStorage.TutorialEvent

local PlayerDataTemplate = {
    --["Name"] = {"ValueObject", defaultValue},
    ["Rowg Coins"] = {"NumberValue", 15000},
    ["Miles Driven"] = {"NumberValue", 0},
    ["Rank"] = {"StringValue", "Permit"},
    ["Ae86"] = {"BoolValue", false},
    ["180SX"] = {"BoolValue", false},
    ["1968 Challenger"] = {"BoolValue", false},
    ["911"] = {"BoolValue", false},
    ["Accord"] = {"BoolValue", false},
    ["Camaro SS"] = {"BoolValue", false},
    ["Corvette Z06"] = {"BoolValue", false},
    ["Huracan Performante"] = {"BoolValue", false},
    ["LFA"] = {"BoolValue", false},
    ["Lancer Evolution"] = {"BoolValue", false},
    ["Miata"] = {"BoolValue", false},
    ["ModelS"] = {"BoolValue", false},
    ["Senna"] = {"BoolValue", false},
    ["Supra"] = {"BoolValue", false}
}

game.Players.PlayerAdded:Connect(function(player)
    local playerKey = "Player-ID:"..player.UserId

    local CarStorage = Instance.new("Folder", player)
    CarStorage.Name = "OwnedCars"
    local leaderstats = Instance.new("Folder", player)
    leaderstats.Name = "leaderstats"
    local RaceHolder = Instance.new("Folder", player)
    RaceHolder.Name = "raceHolder"

    for name, object in pairs(PlayerDataTemplate) do
        local newValue = Instance.new(object[1])
        newValue.Name = name
        newValue.Value = object[2]

        if object[1] == "NumberValue" or object[1] == "StringValue" then
            newValue.Parent = leaderstats
        else
            newValue.Parent = CarStorage
        end
    end

    local GetSave;
    local success, message = pcall(function()
        GetSave = RedlinePlayerDS:GetAsync(playerKey)
    end)

    if success then
        if GetSave then
            print(player.Name.."'s Data = {")
            for _, object in ipairs(CarStorage:GetChildren()) do
                if object:IsA("BoolValue") then
                    print(object.Name, GetSave[object.Name])
                    object.Value = GetSave[object.Name]
                end
            end
            for _, object in ipairs(leaderstats:GetChildren()) do
                if object:IsA("StringValue") or object:IsA("NumberValue") then
                    print(object.Name, GetSave[object.Name])
                    object.Value = GetSave[object.Name]
                end
            end
            print("}")
            print("Data loaded for "..player.Name)
        else
        end
    else
    end
end)

game.Players.PlayerRemoving:Connect(function(player)
    local playerKey = "Player-ID:"..player.UserId

    local CarStorage = player:FindFirstChild("OwnedCars")
    local leaderstats = player:FindFirstChild("leaderstats")
    print(leaderstats["Rowg Coins"].Value, leaderstats["Miles Driven"].Value)

    local tableToSave = {};

    for _, object in ipairs(CarStorage:GetChildren()) do
        if object:IsA("BoolValue") then
            tableToSave[object.Name] = object.Value
        end
    end
    for _, object in ipairs(leaderstats:GetChildren()) do
        if object:IsA("StringValue") or object:IsA("NumberValue") then
        tableToSave[object.Name] = object.Value
        end
    end

    local success, message = pcall(function()
        RedlinePlayerDS:SetAsync(playerKey, tableToSave)
    end)

    if success then
        if message then
            print(message)
        end
        print("saved success for "..player.Name)
    end
end)
0
Also I suck with datastores so that's probably why this is not working lol. Babyseal1015 56 — 5y

Answer this question