Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Car DataStore/DataSave not saving?

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

0

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

1 answer

✓ Accepted answer

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!

1 comment

0

thank you so much!

This discussion is preserved as it was. New answers, comments, and votes are closed.