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!

1 comment
What is userId? Never heard of it. I think you're looking for UserId. userId doesn't exist.