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!

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