here is my script i dont know why it doesnt save

local Data = {}
DataStore = game:GetService("DataStoreService"):GetDataStore("BlastOff2")
repeat wait() until script.Parent.Parent.Owner.Value ~= ''
local BaseRegion
local Base
local Corner
JSON = game:GetService("HttpService")

game.Players.PlayerRemoving:Connect(function(Player)
	if script.Parent.Parent.Owner.Value == Player.Name then
		Base = script.Parent.Parent.Base
		for i, v in pairs(script.Parent.Parent.TestItems:GetChildren()) do
			if v:IsA("Model") then
				local BaseplateOffset = v.PrimaryPart.Position - Base.Position
				table.insert(Data, {
					Name = v.Name;
					Offset = v.PrimaryPart.Position - Base.Position})
			end
		end
		local SaveData = JSON:JSONEncode(Data)
		DataStore:SetAsync(Player.userId, SaveData)
		print(DataStore:GetAsync(Player.userId))
	end
end)

3 comments

0

Tables are automatically encoded to JSON by ROBLOX upon passing them as arguments, there's no need to encode them manually. DataStore:SetAsync(key, {}) will work just fine.

0

Dose it automatically decode them too when you lode it

0

Ok thanks ScriptGuider