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

DataSave not saving at all?

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

0

It’s UserId, not userId, also it’s Connect not connect.

0

The parent argument of instance.new is deprecated, parent the object in another line.

0

The values are all in the player but it just wont save.

0

Did you enabled studio access to API services under Configure Game option?

0

yes

2 answers

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!

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

1 comment

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.

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