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

DataSave not saving at all?

Asked by 5 years ago

Hello. I am making a datasave which saves two (or more) bool values in the player in CarStats. I have two datasave scripts in the game one for money and one for cars (this one). It does not work and i need some help. I try it online in a roblox server and on solo but it still does not work. CarDataSave Script:

local dataStoreService = game:GetService("DataStoreService"):GetDataStore("Earth2DataStore")

game.Players.PlayerAdded:connect(function(plr)
    local key = 'id-'..plr.userId
    local stats = Instance.new('IntValue',plr)
    stats.Name = "CarStats"
    local CamaroOwned = Instance.new('BoolValue',stats)
    CamaroOwned.Name = "CamaroSSOwned"
    local LamOwned = Instance.new('BoolValue',stats)
    LamOwned.Name = "LamborghiniOwned"


    local getSavedData = dataStoreService:GetAsync(key)
    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 = 'id-'..plr.userId
    local save = {plr.CarStats.CamaroSSOwned.Value, plr.CarStats.LamborghiniOwned.Value}
    dataStoreService:SetAsync(key,save)
end)

As you can see it saves two bool values in the player so it knows if the player owns the car. I really need help with this i have been trying to do this for months now. Remember i have tried it in a server! Please help!

0
It’s UserId, not userId, also it’s Connect not connect. User#19524 175 — 5y
0
The parent argument of instance.new is deprecated, parent the object in another line. User#19524 175 — 5y
0
The values are all in the player but it just wont save. RobbieTheUltraGamer 7 — 5y
0
Did you enabled studio access to API services under Configure Game option? awesomeipod 607 — 5y
0
yes RobbieTheUltraGamer 7 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

try making the names for CamaroOwner.Name = CamaroOwned. See if that does anything. Also why is there stats, you don't need that. Just put the owned car boolvalues under plr."

Also, make sure your other scripts that spawn the car turn the value to true. Doing it manually didn't work for me. Make sure the other script does it!

Ad
Log in to vote
0
Answered by 5 years ago

Try going in the "Create" Tab and then going to your game and clicking the setting and then "Configure this game" then turn on API Access

0
i tried doing that but it still does not save the data. Unless i save the data a diffrent way like with tables but i dont know how to do that. RobbieTheUltraGamer 7 — 5y

Answer this question