How to save Part position in the game?

Hello, I would like to know how you can save a Part in the game, saving Part position in the workspace using datastore, someone could tell me? Please :frowning:

local part = workspace.Part
local partPos = part.Position
-- You can use partPos to do stuff

But how do I save the position of the part in datastore?

You can check this out: Documentation - Roblox Creator Hub

I already did it, I know how to do it with int, bool values but I don’t know how to do it with a Part or game objects

You have to save it to a table because you cannot save a vector 3 value to a datastore.

local part = --
local PartPosition = {part.Position.X, part.Position.Y, part.Position.Z}
1 Like

You can save the part properties within a table then in the game make a new part with Instance.new() and change properties.

1 Like

To save a part in datastore is it the same as how I do it with an int value, etc? for example, in this code, should I replace the Gold that I have instantiated with a table and the Part that I want to save with its position?

-- DataStore System
local DataStore = game:GetService("DataStoreService")
local PlayerData = DataStore:GetDataStore("playerGold")

game.Players.PlayerAdded:Connect(function(player)
	local playerFolder = Instance.new("Folder", player)
	playerFolder.Name = "Data"

	local Gold = Instance.new("IntValue", playerFolder)
	Gold.Name = "Gold"

	-- Load data
	local data
	local key = "Player_".. player.UserId
	local success, errormessage = pcall(function()
		data = DataStore:GetAsync(key)
	end)

	-- if success
	if success then
		Gold.Value = data
	elseif data == nil then
		Gold.Value = 0
		print("gold has been saved.")
	else
		print("error saving data, error saving data!!!")
		warn(errormessage)
	end
end)

Yes, something like this:

-- DataStore System
local DataStore = game:GetService("DataStoreService")
local PlayerData = DataStore:GetDataStore("playerGold")

game.Players.PlayerAdded:Connect(function(player)
	local playerFolder = Instance.new("Folder", player)
	playerFolder.Name = "Data"

	local Gold = Instance.new("IntValue", playerFolder)
	Gold.Name = "Gold"

	-- Load data
	local data
	local key = "Player_".. player.UserId
	local success, errormessage = pcall(function()
		data = DataStore:GetAsync(key)
	end)
        print(data)
	-- if success
	if success then
         local part = Instance.new("Part", game.Workspace)
        part.Position = Vector3.new(data[1], data[2], data[3])
	else
		print("error saving data, error saving data!!!")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
        local part = ---
        local partPosition = {part.Position.X, part.Position.Y, part.Position.Z}
         DataStore:SetAsync("Player_"..player.UserId, partPosition)

end)
1 Like

Oh this is perfect, thank you very much! is very helpful, and should I always instantiate the gold object with the Parent to a folder? I can’t instantiate an object to the player without using a folder to save to datastore?

You can’t save the part itself. You need to save the properties and then create a part within a script to loop through the properties and set the same properties.

Also, you should search this, I just googled it:

1 Like

I gotta go for now, I can help you more later. Goodluck!

You can also try making table before that and then save this table in datastore.