I hate datastores

Hello! i am trying to make a system where you can buy/equip skins based on if you have them unlocked, however, for some reason, the “Skins” datastore DOES NOT EXIST. i’ve tried looking at it with a datastore editor, its not there. Ingame it doesnt save anything. I’ve tried prints, i’ve tried manually adding the datastore, nothing. Please help!!

local DataStoreService = game:GetService("DataStoreService")
local Datastore = DataStoreService:GetDataStore("Skins")
print(Datastore)

function YEAHCOMEGETSOME(player)
	local Folder = Instance.new("Folder", player)
	Folder.Name = "Skins"
	print(Datastore:GetAsync(player))
	if Datastore:GetAsync(player) then
		for i,v in pairs(Datastore:GetAsync(player)) do
			print(v)
			local WORKDAMNYOU = game.ReplicatedStorage.Skins:FindFirstChild(v)
			WORKDAMNYOU.Parent = Folder
			print(WORKDAMNYOU)
		end
	end
	if Datastore:GetAsync(player) then
		print("Player has skins!!!")
	else
		local StartingCharacterValue = Instance.new("StringValue")
		StartingCharacterValue.Name = "Default"
		StartingCharacterValue.Parent = Folder
	end

end

function YEAHCOMELOSESOME(player)
	local SaveThese = {}
	for i,v in pairs(player.Skins:GetChildren()) do
		print(v)
		table.insert(SaveThese, {v.Name})
	end
	print(SaveThese)
	Datastore:SetAsync(player, SaveThese)

end


game.Players.PlayerAdded:Connect(YEAHCOMEGETSOME)
game.Players.PlayerRemoving:Connect(YEAHCOMELOSESOME)

where is the script located? scripts wont run under some services

1 Like

The script is in ServerScriptService

i just realized youre using the player instance as the key, the key should be a string (use the userid)

Doesnt work. my issue is that the Skins datastore itself doesnt even begin existing

i just tested your script in studio, it works fine for me, datastore exists, data is loading and saving

is the script parented under anything? was the runcontext changed?

the issue was just that it didnt exist

if not Datastore:GetAsync(tostring(player.UserId)) then
		Datastore:SetAsync(tostring(player.UserId), defaultData)
	end

with defaultData being

local defaultData = {
	["Default"] = true
}
3 Likes

i would do player.UserId as the key for the datastore