This is the saving script. I was just testing if dictionary could be saved, but no. So when the player leaves, I try to save that dictionary into the player's data store.

I looked through mutiple forums but couldn't seem to find the issue

You can ignore the pixeloins save service thing, its just a currency in the game

game.Players.PlayerRemoving:Connect(function(player)
	if game:GetService("RunService"):IsStudio() then return end
	local Pets = {
		Pet1 = {
			Name = "Slimee",
			Attack = 10
		}
	}

local success, failure = pcall(function()
		PixeloinsSaveService:SetAsync(player.UserId.."-pixeloins",player.leaderstats.Pixeloins.Value)
		PetSaveService:SetAsync(player.UserId.."-pets",Pets)
	end)

When player is added:

local pixeloinsData
	local petData
	local success, failure = pcall(function()
		pixeloinsData = PixeloinsSaveService:GetAsync(player.UserId.."-pixeloins") --this works
		petData = PetSaveService:GetAsync(player.UserId.."-pets") -- this doesn't...
	end)
	
	if success then
		pixeloins.Value = pixeloinsData
                print(PetSaveService:GetAsync(player.UserId.."-pets")["Pet1"])
        else end

WHen I print the dictionary, ServerScriptService.PlayerScript:60: attempt to index nil with 'Pet1', so it means that nothing is saved at all... Over here, it's line 10, not line 60

Please help to figure out a way to save the dictionary, all help is appreciated.

Thank you!

[EDIT] So i went on another experience(game), then I tried to save dictionaries (again) and THIS TIME IT PRINTED GIBBERISH this time ill just post the full script

NOTE: THIS IS A COMPLETELY DIFFERENT GAME UNRELATED TO THE ONE ABOVE

local DSS = game:GetService("DataStoreService")
local TDS = DSS:GetDataStore("TableDataStore")

game.Players.PlayerAdded:Connect(function(player)
	
	
	local f = Instance.new("Folder")
	f.Name = "F"
	f.Parent = player
	
	for i = 1,3 do
		local folder = Instance.new("Folder")
		folder.Parent = f
		folder.Name = tostring(i)
		if i == 2 or i == 3 then
			local nf = Instance.new("IntValue")
			nf.Value = 69
			nf.Parent = folder
		end
	end
	
	local data
	local s, e = pcall(function()
		data = TDS:GetAsync(player.UserId.."-table")
	end)
	if s then
		print(data) --printed 0x8491f and a ton of gibberish what that mean
--also when i change it to unpack data it prints out nothing
	end
end)
game.Players.PlayerRemoving:Connect(function(player)
	local ffolder = player.F

	local save = {}
	for i = 1,#(ffolder:GetChildren()) do
		save[tostring(i)] = {
			Name = ffolder[i].Name
		}
		if ffolder[i]:FindFirstChildWhichIsA("IntValue") then
			save[tostring(i)]["Val"] = ffolder[i]:FindFirstChildWhichIsA("IntValue").Value
		end
	end
	local s, e = pcall(function()
		TDS:SetAsync(player.UserId.."-table", save)
	end)
	if s then end
end)

pls help i've been working on this for 3 milion years its giving me headaches and migranes

1 comment

0

OMG LES GOOOO I FOUD IT OUT MYSELF ITS WORKING AOSUHDOOUMSJXIHWPXPANPIJDIPSJPIFPIWJIFJ