How Would I Save a Number Value Inside a Model/Part Using Serialization?

Hey! So I’ve been using zblox164’s placement System V3 (How to use Placement Service) and I currently have a script to save a load a player plot.

However, I want to add a String value into the model that is being loaded/saved, which is also included in the datastore, and I’m not 100% sure how to add this into the serialization/de-serialization function.

Example:
examp

I would want the String value to also be included in the datastore

Saving-Module Code

local module = {}
local Datastore = game:GetService("DataStoreService"):GetDataStore("ModelData", "Version2")

function getPlot(player)
	for i, plot in pairs(game.Workspace.Plots:GetChildren()) do
		if plot.Owner.Value == player.Name then
			return plot.Name

		end
	end
end

--Datastore:SetAsync(player.UserId, models)--
function module.savePlot(player)
	local serial = {}

	local plot = game.Workspace.Plots:FindFirstChild(getPlot(player))
	local ItemHolder = plot.Base.ItemHolder

	local cfi = plot.Base.CFrame:Inverse()
	local children = ItemHolder:GetChildren()

	for i = 1, #children do
		

			serial[tostring(cfi * children[i].PrimaryPart.CFrame)] = children[i].Name


		end
		end
		print(serial)
		Datastore:SetAsync(player.UserId, serial)
	end
	-------------------------------------------------

	function module.loadPlot(player)

		local plot = game.Workspace.Plots:FindFirstChild(getPlot(player))
		plot.Base.ItemHolder:ClearAllChildren()

		local canvasCF = plot.Base.CFrame
		local data = Datastore:GetAsync(player.UserId) or {}

		for cf, name in pairs(data) do
			local model = game.ReplicatedStorage.Models:FindFirstChild(name)
			if (model) then
				local components = {}
				for num in string.gmatch(cf, "[^%s,]+") do
					components[#components+1] = tonumber(num)
				end

				local NewModel = model:Clone()
				NewModel.Parent = plot.Base.ItemHolder
				NewModel.Hitbox.Transparency = 1
				NewModel.Hitbox.CanCollide = false
				NewModel:SetPrimaryPartCFrame(canvasCF * CFrame.new(unpack(components)))

			end
		end
	end


	return module

Any help is appreciated!

1 Like