So I have be trying to make this datastore save this table now for ages and it doesn't seem to work, here is everything you will need:

DataStore Module (It is being called)

local module = {}
	local datastore = game:GetService("DataStoreService"):GetDataStore("Data-3F61CC598CD962DFFA1B88FDF2C79")
	
	local stats = {
		FirstPlay = true;
		Money = 100;
		Level = 0;
		Prestige = 0;
		guns = {"M16"};
		attachments = {};
		skins = {};
	}
	
	game.Players.PlayerAdded:Connect(function(player)
		local savedStats = datastore:GetAsync(player.userId.."-Stats")
		print(savedStats)
		if savedStats ~= nil then
			stats = savedStats
		end
		
		datastore:SetAsync(player.userId.."-Stats",stats)
		
		local sf = Instance.new("Folder",player)
		sf.Name = "Stats"
		
		local F = Instance.new("BoolValue",sf)
		F.Name = "FirstPlay"
		F.Value = stats.FirstPlay
		
		local M = Instance.new("IntValue",sf)
		M.Name = "Money"
		M.Value = stats.Money
		
		local L = Instance.new("IntValue",sf)
		L.Name = "Level"
		L.Value = stats.Level
		
		local P = Instance.new("IntValue",sf)
		P.Name = "Prestige"
		P.Value = stats.Prestige
		
		local G = Instance.new("Folder",sf)
		G.Name = "Guns"
		for i = 1, #stats.guns do
			local GG = Instance.new("StringValue",G)
			GG.Name = "Gun"
			GG.Value = stats.guns[i]			
		end
		
		local A = Instance.new("Folder",sf)
		A.Name = "Attachments"
		for i = 1, #stats.attachments do
			local AA = Instance.new("StringValue",A)
			AA.Name = "Attachment"
			AA.Value = stats.attachments[i]			
		end
		
		local S = Instance.new("Folder",sf)
		S.Name = "Skins"
		for i = 1, #stats.skins do
			local SS = Instance.new("StringValue",A)
			SS.Name = "Skin"
			SS.Value = stats.skins[i][1]
			local SG = Instance.new("StringValue",SS)
			SG.Name = "For"
			SG.Value = stats.skins[i][2]		
		end
	end)
	
	game.Players.PlayerRemoving:Connect(function(player)
		local pStats = player:WaitForChild("Stats")
		local saveGuns = {}
		for i = 1, #pStats.Guns:GetChildren() do
			table.insert(saveGuns, pStats.Guns:GetChildren()[i].Value)
		end
		local saveAttachments = {}
		for i = 1, #pStats.Attachments:GetChildren() do
			table.insert(saveAttachments, pStats.Attachments:GetChildren()[i].Value)
		end
		local saveSkins = {}
		for i = 1, #pStats.Attachments:GetChildren() do
			local skin = {pStats.Attachments:GetChildren()[i].Value,pStats.Attachments:GetChildren()[i].For.Value}
			table.insert(saveSkins, skin)
		end
		
		print(pStats.FirstPlay.Value,pStats.Money.Value,pStats.Level.Value,pStats.Prestige.Value,saveGuns,saveAttachments,saveSkins)
		
		stats.FirstPlay = pStats.FirstPlay.Value
		print(stats.FirstPlay)
		stats.Money = pStats.Money.Value
		stats.Level = pStats.Level.Value
		stats.Prestige = pStats.Prestige.Value
		stats.guns = saveGuns
		stats.attachments = saveAttachments
		stats.skins = saveSkins
		
		print(#stats)
		
		datastore:SetAsync(player.userId.."-Stats",stats)
	end)

return module

Output:

table: 3DA4E16C
false 100 0 0 table: 1FAB5CB4 table: 1FAB5BC4 table: 1FAB5C54
true
0

Stats In Folder: https://gyazo.com/b2297c4a37078b29b89794bb7f4c9549

Help soon would be great! Thanks.

4 comments

0

Have you turned on Studio API Access in configure game or place

0

yes

0

otherwise I would get an error

0

ok