Trying to Datastore a table using DataStore2 doesn't work

Hello, I’m making a Trail shop and inventory system but it only saves one trail and doesn’t save the other trails. This is my first time using DataStore2 yet I know how to use it except for saving tables

I use DataStore2 for this

This is the code

function PlayerDataModule:TrailSave(LocalPlayer)
	local OwnedTrails = {}
	
	local TrailStore = DataStore2Module("Trails", LocalPlayer)
	local GetTrailTable = TrailStore:GetTable(OwnedTrails)
	
	for _, trl in pairs(LocalPlayer.Trails:GetChildren()) do
		table.insert(GetTrailTable, trl.Name)
		TrailStore:Save(GetTrailTable)
		print("Saving...")
	end
	
end

Loading the trails

	local TrailStore = DataStore2Module("Trails", LocalPlayer)
	local GetTrailTable = TrailStore:GetTable(TrailsOwned)
	
	for _, trl in pairs(GetTrailTable) do
		if TrailFolder:FindFirstChild(trl) then
			print(trl)
			local TrailObj = TrailFolder[trl]:Clone()
			TrailObj.Parent = Trails
		end
	end
1 Like

Have you considered using profile service? At this point, I’d recommend it over Datastore2 because it handles possible item duplication glitches, and is overall easier to use.

1 Like
function PlayerDataModule:TrailSave(LocalPlayer)
	local OwnedTrails = {}
	
	local TrailStore = DataStore2Module("Trails", LocalPlayer)
	local GetTrailTable = TrailStore:Get(OwnedTrails)
	
	for _, trl in pairs(LocalPlayer.Trails:GetChildren()) do
		table.insert(GetTrailTable, #GetTrailTable+1, trl.Name)
	end
	
	TrailStore:Set(GetTrailTable); TrailStore:Save()
end

can we answer his question instead…?

1 Like