Save_map Function not Working

I’m making a function that turns models into saved tables but it has not been working.

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_terrain_x_position = {
	26.927,
	26.359,
	98.994,
	26.927,
	-45.141,
	179.03,
	215.27,
	249.27,
	187.07
}

default_bunker_terrain_y_position = {
	-33.383,
	-67.222,
	-67.222,
	-67.222,
	-67.222,
	13.266,
	13.266,
	13.266,
	13.266
}

default_bunker_terrain_z_position = {
	-540.507,
	-468.44,
	-539.798,
	-612.433,
	-540.365,
	332.22,
	571.86,
	191.27,
	396.15
}

default_bunker_terrain_x_size = {
	145.27,
	144.135,
	1.135,
	145.27,
	1.135,
}

default_bunker_terrain_y_size = {
	4.266,
	56.746,
	56.746,
	56.746,
	56.746
}

default_bunker_terrain_z_size = {
	145.27,
	1.135,
	143.851,
	1.419,
	142.716
}

default_bunker_terrain_x_rotation = {0,0,0,0,0,0,0,0,0}

default_bunker_terrain_y_rotation = {-90,0,-90,0,0,0,0,0,0}

default_bunker_terrain_z_rotation = {0,0,0,0,0,0,0,0,0}

default_bunker_materials = {
	"Mud",
	"Rock",
	"Rock",
	"Rock",
	"Rock",
	"Grass",
	"Grass",
	"Grass",
	"Grass"
}

DataStore2.Combine(
 "Test1", "Wins", "Ωmega Coins", "Likes", "bunker_name", "object_name",
 "object_x_position", "object_y_position", "object_z_position", "object_x_rotation", "object_y_rotation",
 "object_z_rotation", "terrain_x_position", "terrain_y_position", "terrain_z_position", "terrain_x_rotation",
 "terrain_y_rotation", "terrain_z_rotation", "terrain_x_size", "terrain_y_size", "terrain_z_size", "terrain_materials"
)

Players.PlayerAdded:Connect(function(Player)
	winsStore = DataStore2("Wins", Player)
	coinStore = DataStore2("Ωmega Coins", Player)
	likesStore = DataStore2("Likes", Player)
	
	
	bunkernameStore = DataStore2("bunker_name", Player)
	
	
	objectnameStore = DataStore2("object_name", Player)
	
	objectxpositionStore = DataStore2("object_x_position", Player)
	objectypositionStore = DataStore2("object_y_position", Player)
	objectzpositionStore = DataStore2("object_z_position", Player)

	
	objectxrotationStore = DataStore2("object_x_rotation", Player)
	objectyrotationStore = DataStore2("object_y_rotation", Player)
	objectzrotationStore = DataStore2("object_z_rotation", Player)

	
	terrainxpositionStore = DataStore2("terrain_x_position", Player)
	terrainypositionStore = DataStore2("terrain_y_position", Player)
	terrainzpositionStore = DataStore2("terrain_z_position", Player)
	
	terrainxrotationStore = DataStore2("terrain_x_rotation", Player)
	terrainyrotationStore = DataStore2("terrain_y_rotation", Player)
	terrainzrotationStore = DataStore2("terrain_z_rotation", Player)

	
	terrainxsizeStore = DataStore2("terrain_x_size", Player)
	terrainysizeStore = DataStore2("terrain_y_size", Player)
	terrainzsizeStore = DataStore2("terrain_z_size", Player)

	terrainmaterialsStore = DataStore2("terrain_materials", Player)
	
	local played = Instance.new("BoolValue", Player)
	played.Name = "played"
	if terrainmaterialsStore[1] then
		played = true
	end
	
	local leaderstats = Instance.new("Folder") do
		leaderstats.Name = "leaderstats"
	end
	local wins = Instance.new("IntValue") do
		wins.Name = "Wins"
		wins.Parent = leaderstats
	end
	local omega_coins = Instance.new("IntValue") do
		omega_coins.Name = "O$"
		omega_coins.Parent = leaderstats
	end
	local likes = Instance.new("IntValue") do
		likes.Name = "Likes"
		likes.Parent = leaderstats
	end
	leaderstats.Parent = Player
	
	function save_to_model(player, bunkernameStore) ---------------------------------------------------- function start
	local newMap = ServerStorage.empty_map:Clone() do
		newMap.Name = Player.Name
		local name = Instance.new("StringValue", newMap.params)
		if bunkernameStore then
			name.Value = bunkernameStore
			else
			name.Value = "Bunker Construction Site"
		end
		local offset = Instance.new("NumberValue", newMap.params)
		--offset.Value = Player:WaitForChild("designated_bunker_position")
	end
	local terrain = newMap.terrain:WaitForChild("cubes")
	for i, v in pairs(terrainmaterialsStore:Get(default_bunker_materials)) do
		print (i) print(v)
		local Part = Instance.new("Part") do
			Part.Name = v
			Part.CFrame = CFrame.new(
			 terrainxpositionStore:Get(default_bunker_terrain_x_position)[i],
			 terrainypositionStore:Get(default_bunker_terrain_y_position)[i],
			 terrainzpositionStore:Get(default_bunker_terrain_z_position)[i]
			)
			
			
			Part.Size = Vector3.new(
			 terrainxsizeStore:Get(default_bunker_terrain_x_size)[i],
			 terrainysizeStore:Get(default_bunker_terrain_y_size)[i],
			 terrainzsizeStore:Get(default_bunker_terrain_z_size)[i]
			)
			
			Part.Orientation = Vector3.new(
			 terrainxrotationStore:Get(default_bunker_terrain_x_rotation)[i],
			 terrainyrotationStore:Get(default_bunker_terrain_y_rotation)[i],
			 terrainzrotationStore:Get(default_bunker_terrain_z_rotation)[i]
			)
			
			
			Part.Parent = terrain
			Part.Anchored = true
			Part.Transparency = 1
			Part.CanCollide = false
			newMap.Parent = workspace.maps
		end
	end  --------------------------------------------------------------------------------------------- function end
	
		function model_to_save(new_name) ---------------------------------------------------------function start (THIS FUNCTION)
		if game.Players.LocalPlayer.PlayerScripts.loaded_map == game.Players.LocalPlayer.Name then
			local terrain = workspace.maps[Player.Name].terrain:WaitForChild("cubes"):GetChildren()
			else
				local terrain = ReplicatedStorage.local_map_storage[Player.Name].terrain:WaitForChild("cubes"):GetChildren()
		end
		
		bunkernameStore = new_name

for i = 1, #terrain do
		local child = terrain[i]
		
		if child:IsA("Part") then
			terrainxpositionStore[i] = child.Position.X
			terrainypositionStore[i] = child.Position.Y
			terrainzpositionStore[i] = child.Position.Z
			
			terrainxrotationStore[i] = child.Rotation.X
			terrainyrotationStore[i] = child.Rotation.Y
			terrainzrotationStore[i] = child.Rotation.Z
			
			
			terrainxsizeStore[i] = child.Size.X
			terrainysizeStore[i] = child.Size.Y
			terrainzsizeStore[i] = child.Size.Z
			
			
			terrainmaterialsStore[i] = child.Name
		end
	end -------------------------------------------------------------------------------------------function end

end
end

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

ReplicatedStorage:WaitForChild("save_map").OnServerEvent:Connect(function(name)
	model_to_save(name)
end)
	
	
end)





SaveinStudio is on.

What exactly is wrong with the script?

I’ll highlight the function. The data just doesnt get saved and I have confirmed that the function that converts a save to a model is working.

Ok just realized something, I’m not properly updating the datastore I should be using a function like :Increment() but actually I want to set a value instead and I can’t find the function now, I’ll do a bit more research and I have no idea how to use these functions on tables.