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

DataStore not saving data?

I'm trying to make a skin system that saves the values of your skins. When testing, however, my script didn't work, and I kept getting the error print. Here is my script:

local DSS = game:GetService("DataStoreService")
local SkinDataStore = DSS:GetDataStore("SkinStore")

game.Players.PlayerAdded:Connect(function(player)
	wait(1)
	local Skins = Instance.new("Folder")
	Skins.Name = "Skins"
	Skins.Parent = player
	
	local RoyaleMtar = Instance.new("StringValue")
	RoyaleMtar.Name = "RoyaleMtar"
	RoyaleMtar.Parent = Skins
	local DesertPGH = Instance.new("StringValue")
	DesertPGH.Name = "DesertPGH"
	DesertPGH.Parent = Skins
	
	local Id = "Player_"..player.UserId
	local SkinData
	local success, errormessage = pcall(function()
		SkinData = SkinDataStore:SetAsync(Id)
	end)
	if success then
		RoyaleMtar.Value = SkinData
		DesertPGH.Value = SkinData
		print("hi" )
	else
		print("error")
		warn(errormessage)
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local Id = "Player_"..player.UserId
	local data = player.Skins.RoyaleMtar.Value
	local data1 = player.Skins.DesertPGH.Value
	
	local success, errormessage = pcall(function()
		SkinDataStore:SetAsync(Id, data, data1)
	end)
	if success then
		print("Skins Saved")
	else
		print("Skins failed to save")
		warn(errormessage)
	end
end)

1 answer

✓ Accepted answer

You seem to have accidentally put SetAsync on line 20 where you actually want to use GetAsync. Also, you are using SetAsync incorrectly, I would recommend using a dictionary to store multiple things

like so

SkinDataStore:SetAsync(Id, {
	RoyaleMtar = data,
	DesertPGH = data1
})

and retrieve the data like this

local SkinData
local success, errormessage = pcall(function()
	SkinData = SkinDataStore:GetAsync(Id)
end)
if success then
	RoyaleMtar.Value = SkinData.RoyaleMtar
	DesertPGH.Value = SkinData.DesertPGH
	print("hi" )
else
	print("error")
	warn(errormessage)
end

Wiki:

Dictionaries

SetAsync

GetAsync

Don't forget to mark my answer as the solution and upvote it if it answered your question :)

1 comment

1

ah! ty, ill test it.

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