How to save positions of players placed posessions

Im terrible at data stores, but im trying to make a game where a player can place objects, lets say places a couch, then rejoins and the couch is still placed. You see, this is where im stuck. How can i save the couchs position relative to the players plot that theyre given? Im pretty sure vector 3 cannot be saved in a data store, so im not exactly sure how to save the couchs position. Plus, what if a player rejoins and get plot 3 instead of plot 1? I dont want the players couch to load back onto plot 1.

I also need to save the attributes ive parented to objects, for example the weight of the couch needs to save. Im assuming this would be pretty straightforward though? So saving the position is my main concern here

I do have a function that can detect which plot is the players, but, like i said, how can i save this data?

So far, ive tried having the placed objects parented to a folder named after the player, then trying to save it like that. And, after that failed, i asked AI/google what to do and it lied to me so, yeah.

Thanks for all help and tips, because i really am stumped on this concept.

1 Like

i think you can just save the cframe then use PrimaryPart:PivotTo(plot:ToWorldSpace(part position from datastore))
you can also save everything in a table like this:
{model = whatever, position = model.PrimaryPart.CFrame, other data = something}

3 Likes

Okay thanks, ill try it out tomorrow.

1 Like

Basic steps for saving data in Roblox:

  • Use DataStoreService - a service for storing data between sessions.
  • Store data as tables - DataStores can save tables that are automatically serialized into JSON.
  • To store the object’s position, use Vector3 - DataStore does not save Vector3 directly, but it can be split into three numbers (X, Y, Z) and saved as separate values.
  • Handling attributes - you can save them in the table in the same way as the position.

How to save the position of an object (a sofa):

local DataStoreService = game:GetService("DataStoreService")
local FurnitureDataStore = DataStoreService:GetDataStore("FurniturePositions")  -- the name of your DataStore

-- Let's say you have a sofa object.
local sofa = workspace:WaitForChild("Sofa")
local playerId = "player123" -- or the unique identifier of the player

-- When do you want to save a position:
local function saveSofaPosition(playerId, sofaObject)
    local position = sofaObject.Position
    local data = {
        X = position.X,
        Y = position.Y,
        Z = position.Z,
        -- You can add other attributes here, such as weight
        -- The weight can be taken from an attribute or property of an object
        Weight = sofaObject:GetAttribute("Weight") -- example
    }
    local success, err = pcall(function()
        FurnitureDataStore:SetAsync(playerId .. "_sofa", data)
    end)
    if not success then
        warn("Data saving error: " .. err)
    end
end

How to load the position and attributes:

local function loadSofaPosition(playerId, sofaObject)
    local success, data = pcall(function()
        return FurnitureDataStore:GetAsync(playerId .. "_sofa")
    end)
    if success and data then
        local position = Vector3.new(data.X, data.Y, data.Z)
        sofaObject.Position = position
        if data.Weight then
            sofaObject:SetAttribute("Weight", data.Weight)
        end
    else
        warn("Data could not be uploaded or there is no data")
    end
end

Pay attention:

  • Player ID - it is better to use a unique ID or player name.
  • Objects are saved by keys associated with the player, such as "playerId_sofa" - this helps to avoid confusion if the player has multiple objects.
  • Error handling - be sure to use pcall to avoid crashing the game.

Regarding the plot (for example, if the player receives another plot):

  • You can save the position of the sofa relative to the plot or separately — for example, you can save the position of the sofa independently from the plot.
  • Then, when you load the scene, you can simply set the sofa to the saved position.

Result:

  • Use DataStore to store data.
  • Save the position as three numbers (X, Y, Z).
  • Load and restore the position when you enter.
  • Save attributes in the same way as you save the position.
2 Likes

Thank you for the advice, i did not know that you fould save the position as seperate values then make them back into a vector 3, so thanks :slight_smile:

1 Like

Thank you for this, it took me a while to mark you as the solution because i kept messing up my datastore and nothing was working lol. But this is a way i used that worked, so thanks :slight_smile:

I tested your method and it works as well, i know i didnt mark you as the solution but i still wanted to say thank you :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.