Datastore not saving

I fire this when the player leaves, however it does not save. I get no errors, just the first print and that’s it

print('saving') -- This prints
-- Save the current house under the house name
HouseDataStore:SetAsync(player.UserId .. ' - ' .. PlayerData.House.Value, Items)
print('saved') -- Does not print

Did you enabled “Enable Studio to Access to API Services” in options?

Yes
30 characters30 characters30 characters30 characters30 characters30 characters30 characters30 characters

Test it in ingame not in studio

1 Like

You can’t store objects in DataStores, but I assume the “Items” is a table? I suggest showing the whole script.

return function(player)
	-- Get players plots
	local PlayersExterior = Exteriors:FindFirstChild(player.Name)
	if not PlayersExterior then return end
	
	local PlayersInterior = Interiors:FindFirstChild(player.Name)
	if not PlayersInterior then return end
	
	-- Setup a reference table to store later
	local Items = {Exterior = {}, Interior = {}, Landscape = {}, Furniture = {}}
	
	-- Get the exterior colors
	for _, v in pairs(PlayersExterior.Build:GetDescendants()) do
		if v:IsA('Color3Value') then
			Items.Exterior[v.Parent.Name] = {math.floor(v.Value.R * 255), math.floor(v.Value.G * 255), math.floor(v.Value.B * 255)}
		end
		
		-- Get mailbox
		if v.Name == 'Mailbox' then
			local MailboxData = {}
			
			MailboxData = CFrameToTable(PlayersExterior.PrimaryPart.CFrame:ToObjectSpace(PlayersExterior.Build.Mailbox.PrimaryPart.CFrame))
			
			Items.Exterior['Mailbox'] = MailboxData
		end
	end
	
	-- Get exterior items
	for _, item in pairs(PlayersExterior.Build.Landscape:GetChildren()) do
		local ItemData = {}
		local PrimaryPart = item.PrimaryPart
		
		ItemData.ItemName = item.Name
		
		ItemData.Position = CFrameToTable(PlayersExterior.PrimaryPart.CFrame:ToObjectSpace(PrimaryPart.CFrame))
		
		local Primary = item:FindFirstChild('Primary')
		if Primary then
			ItemData.Primary = Primary.BrickColor.Name
		
			local Secondary = item:FindFirstChild('Secondary')
			if Secondary then
				ItemData.Secondary = Secondary.BrickColor.Name
			end
		end
		
		Items.Landscape[#Items.Landscape + 1] = ItemData
	end
	
	-- Get the furniture
	for _, item in pairs(PlayersInterior.Build.Furniture:GetChildren()) do
		local ItemData = {}
		local PrimaryPart = item.PrimaryPart
				
		ItemData.ItemName = item.Name
		
		ItemData.Position = CFrameToTable(PlayersInterior.PrimaryPart.CFrame:ToObjectSpace(PrimaryPart.CFrame))
				
		local Primary = item:FindFirstChild('Primary')
		ItemData.Primary = {math.floor(Primary.Color.Value.R * 255), math.floor(Primary.Color.Value.G * 255), math.floor(Primary.Color.Value.B * 255)}
		
		local Secondary = item:FindFirstChild('Secondary')
		if Secondary then
			ItemData.Secondary = {math.floor(Secondary.Color.Value.R * 255), math.floor(Secondary.Color.Value.G * 255), math.floor(Secondary.Color.Value.B * 255)}
			
			local Tertiary = item:FindFirstChild('Tertiary')
			if Tertiary then
				ItemData.Tertiary = {math.floor(Tertiary.Color.Value.R * 255), math.floor(Tertiary.Color.Value.G * 255), math.floor(Tertiary.Color.Value.B * 255)}
			end
		end
		
		Items.Furniture[#Items.Furniture + 1] = ItemData
	end
	
	-- Get the floor and wall textures 
	for _, room in pairs(PlayersInterior.Build.InteriorElements:GetChildren()) do
		-- Save the floor and wall for each individual room number
		Items.Interior[room.Name] = {}
		Items.Interior[room.Name].Floor = string.match(room.Floor.Texture.Texture, '%d+')
		Items.Interior[room.Name].Walls = string.match(room.Wall.Texture.Texture, '%d+')
	end
	
	local PlayerData = player:FindFirstChild('PlayerData')
	if not PlayerData then return end
	print('saving')
	-- Save the current house under the house name
	HouseDataStore:SetAsync(player.UserId .. ' - ' .. PlayerData.House.Value, Items)
	print('saved')
end