Can someone explain this?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

i want to get data and turn it into a table, then when i want to save the data, i turn it back into a table

  1. What is the issue? Include screenshots / videos if possible!

Can someone explain this?


LIKE WHY IS IT DOING THAT LIKE 5K TIMES ITS LITTERLY THE FIRST TIME, THERE IS NO ERRORS…

print(game.GameId)

local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService"):GetDataStore("Data")
local HTTP = game:GetService("HttpService")
local Dummy = workspace.NPC.Worker
local TableFolder = require(game.ReplicatedStorage.TableFolderConverter)

Players.PlayerAdded:Connect(function(plr)
	
	
	local plrId = plr.UserId
	local des = Players:GetHumanoidDescriptionFromUserId(plrId)
	if des then
		Dummy.Humanoid:ApplyDescription(des)
		wait(1)
		local PickClone = script.PickaxeSpawnPart:Clone()
		PickClone.Name = "PickaxeSpawnPart"
		PickClone.Parent = Dummy
	end
	Dummy.Name = plr.Name
	
	
	local l = Instance.new("Folder", plr)
	l.Name = "Stats"
	local StatsSystem = Instance.new("Folder", game.ReplicatedStorage.PlrData)
	StatsSystem.Name = plr.Name
	local c = Instance.new("NumberValue", l)
	c.Name = "Cash"
	c.Value = 0
	local r = Instance.new("NumberValue", l)
	r.Name = "Rebirths"
	r.Value = 0
	local p = Instance.new("NumberValue", l)
	p.Name = "Prestiges"
	p.Value = 0
	local m = Instance.new("NumberValue", l)
	m.Name = "Metals"
	m.Value = 0
	
	local StatsTable = {
		Cash = c.Value,
		Rebirths = r.Value,
		Prestiges = p.Value,
		Metals = m.Value
	}
	
	local ButtonTable = {
		Button1 = true,
		Button2 = false,
		Button3 = false,
		Button4 = false,
	}
	
	local LeaderboardTable = {
		L1 = true,
		L2 = false,
		L3 = false,
		L4 = false,
	}
	
	local DataTable = {
		StatsFolder = StatsTable,
		Buttons = ButtonTable,
		Leaderboards = LeaderboardTable
	}
	
	local s,e = pcall(function()
		if HTTP:JSONDecode(DSS:GetAsync(plr.UserId)) == nil or "" or {} then
			DataTable = {
				StatsFolder = StatsTable,
				Buttons = ButtonTable,
				Leaderboards = LeaderboardTable
			}
			print(DataTable)
		else
			DataTable = HTTP:JSONDecode(DSS:GetAsync(plr.UserId))
			print(DataTable)
		end
	end)
	
	print(s, e, DataTable)
	
	TableFolder:_ToInstance(DataTable, game.ReplicatedStorage.PlrData:FindFirstChild(plr.Name))
	
	wait(5)
	
	while wait() do
		for Type, Tables in DataTable do
			if Type == "StatsFolder" then
				for Item, Value in Tables do
					if Item == c.Name then
						Tables[Item] += 10000
						c.Value = Tables[Item]
					elseif Item == r.Name then
						r.Value = Tables[Item]
					elseif Item == p.Name then
						p.Value = Tables[Item]
					elseif Item == m.Name then
						m.Value = Tables[Item]
					end
				end
			end
		end
		
		TableFolder:_ToInstance(DataTable, game.ReplicatedStorage.PlrData:FindFirstChild(plr.Name))
	end
end)

Players.PlayerRemoving:Connect(function(plr)
	local BackToTable = TableFolder:_ToTable(game.ReplicatedStorage.PlrData:FindFirstChild(plr.Name))
	DSS:SetAsync(plr.UserId, HTTP:JSONEncode(BackToTable))
	print(BackToTable)
end)

game:BindToClose(function()
	wait(5)
end)
  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i honestly dont know what to do

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Check if the GetAsync is successful before Encoding/Decoding.

that function (TableFolder:_ToInstance) you’re calling is in a while wait() loop (with no number) which means it’ll be running a lot, like a lot a lot, infinitely until you can stop it

It’s not doing it 5k times, that’s just the console limit. it’s most likely going on forever.

while wait() do
		for Type, Tables in DataTable do
			if Type == "StatsFolder" then
				for Item, Value in Tables do
					if Item == c.Name then
						Tables[Item] += 10000
						c.Value = Tables[Item]
					elseif Item == r.Name then
						r.Value = Tables[Item]
					elseif Item == p.Name then
						p.Value = Tables[Item]
					elseif Item == m.Name then
						m.Value = Tables[Item]
					end
				end
			end
		end
		
		TableFolder:_ToInstance(DataTable, game.ReplicatedStorage.PlrData:FindFirstChild(plr.Name))
	end

I’d like to clarify that here, there isn’t a break so it will continue in that while loop for eternity, even when the player leaves (which it will most likely stop due to an error regarding the lack of a player, but it’s still not something to rely upon.)

i have a new error now, i dont know if its related or not but i got “tables cant be cyclic”

local Types = {
	["string"] = "StringValue";
	["number"] = "NumberValue";
	["boolean"] = "BoolValue";
	["BrickColor"] = "BrickColorValue";
	["Instance"] = "ObjectValue";
	["Vector3"] = "Vector3Value";
	["CFrame"] = "CFrameValue";
	["Color3"] = "Color3Value";
	["Ray"] = "RayValue";
};

local Config = require(script.Config)

local module = {}

function module:ToInstance(TableToReplace, Parent)
	for i, v in TableToReplace do
		
		if type(v) == "table" then
			if Parent:FindFirstChild(i) then
				local CurrentObject = Parent:FindFirstChild(i)
				module:ToInstance(v, CurrentObject)
			else
				local NewObject = Instance.new("Folder")
				NewObject.Parent = Parent
				NewObject.Name = i
				module:ToInstance(v, NewObject)
			end
		else
			for i2,v2 in pairs(Types) do
				if type(v) == i2 then
					if Parent:FindFirstChild(i) then
						local CurrentObject = Parent:FindFirstChild(i)
						CurrentObject.Value = v
					else
						local currentValue = Instance.new(v2)
						currentValue.Parent = Parent
						currentValue.Name = i
						currentValue.Value = v
					end
				end
			end
		end
	end
end

function module:ToTable(Object)
	local TableToReturn = {}
	local function Convert(NewParent)
		for i, v in NewParent:GetChildren() do
			if v:IsA("Folder") or v:IsA("Configuration") then
				TableToReturn[v.Name] = Convert(v)
			else
				TableToReturn[v.Name] = v.Value
			end
		end
		
		return TableToReturn
	end
	
	local Start = Convert(Object)
	return Start
end

return module

this is the code for the module if you needed