Datastore2 Table Returns Nil

I’m making a script that converts saved maps to models. When I call the datastore for the position that newly instanced baseparts go to (which :FillBlock() is then called on) the game errors:

14:22:11.485 - ServerScriptService.save_script:98: bad argument #3 (CFrame expected, got nil)

I made sure that the function was in the PlayerAdded event which it wasn’t. I changed it and also made it print the value of the terrain position datastore and it said it printed a table and I also printed the 1st value in the table which is nil, so I have a table filled with nil values.

DataStore2 = require(game:GetService("ServerScriptService").DataStore2)
ServerStorage = game:GetService("ServerStorage")
Players = game:GetService("Players")
ReplicatedStorage = game.ReplicatedStorage

default_omega_coins, default_likes, default_wins = 0, 0, 0

default_bunker_name = "Bunker"

default_bunker_terrain_position = {, -33.383, -435.507),, 23.365, -572.788),, 23.365, -434.153),, 23.365, -435.236),, 23.365, -297.955)
default_bunker_terrain_size = {, 8.143, 277.27),, 108.309, 2.708),, 108.309, 274.562),, 108.309, 272.396),, 108.309, 2.166)
default_bunker_terrain_rotation = {
	CFrame.Angles(0, 0, 0),
	CFrame.Angles(0, 0, 0),
	CFrame.Angles(0, 0, 0),
	CFrame.Angles(0, 0, 0),
	CFrame.Angles(0, 0, 0)
default_bunker_materials = {

default_object_name, default_object_position, default_object_rotation = {}, {}, {}

DataStore2.Combine("Ham", "Wins", "Ωmega Coins", "Likes", "bunker_name", "object_name", "object_position", "object_rotation", "terrain-position", "terrain_rotation", "terrain_size", "terrain_materials")

	winsStore = DataStore2("Wins", Player)
	coinStore = DataStore2("Ωmega Coins", Player)
	likesStore = DataStore2("Likes", Player)
	bunkernameStore = DataStore2("bunker_name", Player)
	objectnameStore = DataStore2("object_name", Player)
	objectpositionStore = DataStore2("object_position", Player)
	objectrotationStore = DataStore2("object_rotation", Player)
	terrainpositionStore = DataStore2("terrain-position", Player)
	terrainrotationStore = DataStore2("terrain_rotation", Player)
	terrainsizeStore = DataStore2("terrain_size", Player)
	terrainmaterialsStore = DataStore2("terrain_materials", Player)
	print (terrainpositionStore)
	local new_player ="BoolValue", Player)
	new_player.Name = "new_player"
	if winsStore == nil then
		new_player = true
	local leaderstats ="Folder") do
		leaderstats.Name = "leaderstats"
	local wins ="IntValue") do
		wins.Name = "Wins"
		wins.Parent = leaderstats
	local omega_coins ="IntValue") do
		omega_coins.Name = "Ωmega $"
		omega_coins.Parent = leaderstats
	local likes ="IntValue") do
		likes.Name = "Likes"
		likes.Parent = leaderstats
	leaderstats.Parent = Player
	function save_to_model(player, bunker_name) ---------------------------------------------------- function start
	local newMap = ServerStorage.empty_map:Clone() do
		newMap.Name = Player.Name
		local name ="StringValue", newMap.params)
		name.Value = bunker_name
		local offset ="NumberValue", newMap.params)
		--offset.Value = Player:WaitForChild("designated_bunker_position")
	local terrain = newMap.terrain:WaitForChild("cubes")
	for i, v in pairs(terrainmaterialsStore:Get(default_bunker_materials)) do
		print (i) print(v)
		local Part ="Part") do
			Part.Name = v
			print(terrainpositionStore:Get(default_object_position)) -- errors
			Part.CFrame = terrainpositionStore:Get(default_object_position)[i]
			Part.Size = terrainsizeStore:Get(default_bunker_terrain_size)[i]
			Part.Parent = terrain
			Part.Anchored = true
			Part.Transparency = 1
			newMap.Parent = workspace.maps
	end  --------------------------------------------------------------------------------------------- function end
		function model_to_save(new_name)	
		local terrain = workspace.maps[Player.Name]terrain:WaitForChild("cubes")
		bunkernameStore = new_name

for i = 1, #terrain do
		local child = terrain[i]
		if child:IsA("Part") then
			terrainpositionStore[i] = child.Position
			terrainrotationStore[i] = child.Rotation
			terrainsizeStore[i] = child.Size
			terrainmaterialsStore[i] = child.Name

ReplicatedStorage:WaitForChild("load_map").OnServerEvent:Connect(function(player, bunker_name)
	save_to_model(player, bunker_name)

Mind marking which line errors?

Ok I am going to edit the post now.

Ok it turns out this is partially I used the object store instead of the terrain store. I really need to learn to spot these dumb mistakes.

I just realized I need to further serialize the CFrame values.

In ServerScriptService inside save_script on line 98 you should get CFrame but you got nil. Inside function :FillBlock() you have to insert some parameters which you can find which ones inside this API reference article.

1 Like

Nope nope all solved. It took a while but I serialized the CFrames and it worked. Also my load_map function is working fine right now, which is where I use :FillBlock().