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

Car DataStore/DataSave not saving?

Asked by 6 years ago

Hello. I have been trying so hard to get this script working but so far not good. I am trying to save bool values in a folder in the player to see if the player own the car or not. Here is the script:

local dataStoreService = game:GetService("DataStoreService"):GetDataStore("CarDataStore")
local prefix = 'usr_'

game.Players.PlayerAdded:Connect(function(plr)
    local key = prefix..plr.userId
    local CamaroOwned = Instance.new('BoolValue',plr)
    CamaroOwned.Name = "CamaroSSOwned"
    local LamOwned = Instance.new('BoolValue',plr)
    LamOwned.Name = "LamborghiniOwned"

    local getSavedData = dataStoreService:GetAsync(key)
    for i, v in pairs(getSavedData) do print(i, v) end
    if getSavedData then
        CamaroOwned.Value = getSavedData[1]
        LamOwned.Value = getSavedData[2]
    else
        local saving = {CamaroOwned.Value, LamOwned.Value}
        dataStoreService:SetAsync(key,saving)
    end
end)

game.Players.PlayerRemoving:Connect(function(plr)
    local key = prefix..plr.userId
    local save = {plr.CamaroSSOwned.Value, plr.LamborghiniOwned.Value}
    for i, v in pairs(save) do print(i, v) end
    dataStoreService:SetAsync(key,save)
end)

nothing saves in the script when i go onto another server so it just does not save. I have been trying for months now. I am trying to make a one time purchase car system. Please give me a descriptive and helpful awnser! Please help!

0
What is userId? Never heard of it. I think you're looking for UserId. userId doesn't exist. User#19524 175 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

Do you have any errors in output? If not write this on the top of your script!

game:BindToClose(function() wait(5) end))

this will give the script time to save!

0
thank you so much! RobbieTheUltraGamer 7 — 6y
Ad

Answer this question