Table.unpack not working

Hello!
I was storing CFrames in data store and i encountered a problem. whenever i run the function it says: ServerScriptService.Modules.MainModule:10: invalid argument #1 to ‘unpack’ (table expected, got nil). I have a script and isk whats not working.

Script (part of it):

function module:LoadMap(X, Z, Seed, IslandWidth, IslandMass, newMap)

	local function CFrameToTable(cf)
		return {cf:GetComponents()}
	end
	local function TableToCFrame(t)
		return CFrame.new(table.unpack(t))
	end
	local 

here is an object i am inserting:

Main.Objects.Trees["Chunk "..x..z] = CFrameToTable(Tree.Base.CFrame)

Can you show the part of the code where TableToCFrame is used?

Tree:SetPrimaryPartCFrame(TableToCFrame(Main.Objects.Trees["Chunk "..x..z]))

Main.Objects.Trees["Chunk "..x..z] is nil, maybe you didn’t get the data from the datastore correctly?

Im getting all the data in the game, there are no errors.

script:

function module:LoadGameData()
	local GameData = require(game:GetService("ServerScriptService").Modules.GameData)
	local DataStore = game:GetService("DataStoreService"):GetDataStore(GameData.ServerCode)
	local Players = game:GetService("Players")
	local tries = 3
	local Resources, Rocks, Trees
	local succ, err

	local function Get()
		local count = 0
		repeat
			succ, err = pcall(function()
				Resources = DataStore:GetAsync("Resources")
				Rocks = DataStore:GetAsync("Rocks")
				Trees = DataStore:GetAsync("Trees")
			end)
			count += 1
		until count >= tries or succ

		if not succ then
			warn("Failed to load Server:"..GameData.ServerCode.." kicking all players...")
			warn(err)
			for i, v in pairs(Players:GetPlayers()) do
				v:Kick("\n\n Failed to load Server. kicking all players - Rejoin to load back. \n\n")
			end
			return
		end
		if succ then
			if Resources and Trees and Rocks then
				return {Resources, Trees, Rocks}
			else
				return {
					{
						["Wood"] = GameData.Wood,
						["Iron"] = GameData.Iron,
						["CitizenCount"] = GameData.CitizenCount,
						["Coal"] = GameData.Coal,
						["Gold"] = GameData.Gold,
						["Food"] = GameData.Food,
						["Water"] = GameData.Water,
						["Stone"] = GameData.Stone,
					},
					{["Rocks"] = GameData.Objects.Rocks},
					{["Trees"] = GameData.Objects.Trees}
				}
			end
		end
	end

	local function Set()
		local Values = Get()
		local count = 0
		local succ, err
		local Resources = {
			["Wood"] = GameData.Wood,
			["Iron"] = GameData.Iron,
			["CitizenCount"] = GameData.CitizenCount,
			["Coal"] = GameData.Coal,
			["Gold"] = GameData.Gold,
			["Food"] = GameData.Food,
			["Water"] = GameData.Water,
			["Stone"] = GameData.Stone,
		}
		local Rocks = {["Rocks"] = GameData.Objects.Rocks}
		local Trees = {["Trees"] = GameData.Objects.Trees}
		Resources.Wood = Values.Wood
		Resources.Iron = Values.Iron
		Resources.CitizenCount = Values.CitizenCount
		Resources.Coal = Values.Coal
		Resources.Gold = Values.Gold
		Resources.Food = Values.Food
		Resources.Water = Values.Water
		Resources.Stone = Values.Stone
		Rocks.Rocks = Values.Rocks
		Trees.Trees = Values.Trees
		repeat
			succ, err = pcall(function()
				DataStore:SetAsync("Resources", Resources)
				DataStore:SetAsync("Rocks", Rocks)
				DataStore:SetAsync("Trees", Trees)
			end)
			count += 1
		until count >= tries or succ

		if not succ then
			warn("Failed to Set Server:"..GameData.ServerCode)
			warn(err)
			return
		end
		print(GameData.Objects.Trees)
		warn("\n\n Game Data Has Loaded or Been Set! No Errors At All! Woohoo! \n\n")
	end
	Set()
end
```

I have found the problem to the table.unpack, i was not checking if their was a nil value, now i am.

1 Like

how do you do this?

function Signal:Connect(handler)
	if not (type(handler) == "function") then
		error(("connect(%s)"):format(typeof(handler)), 2)
	end

	return self._bindableEvent.Event:Connect(function()
		local handler = unpack(self._argData, 1, self._argCount)
	end)
end

--- Wait for fire to be called, and return the arguments it was given.
-- @treturn ... Variable arguments from connection
function Signal:Wait()
	self._bindableEvent.Event:Wait()
	assert(self._argData, "Missing arg data, likely due to :TweenSize/Position corrupting threadrefs.")
	return unpack(self._argData, 1, self._argCount)
end

i dont know what do i do wrong, i have the same issue and the same line in output