Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I save properties of an instance with datastore?

I've looked at the developer hub article and i'm still left confused.

Basically I want to save the properties of an instance, such as a number value or bool value, and have those saved by datastore, and when a player joins it changes the properties of the instance to what was saved, anybody know a good place to start with this?

1 answer

Personally, if I were to attempt to upload the properties of an Instance, I would create a array of each property I wish to iterate through, and create a function to return a dictionary of each value for upload to our DataStore

local DataStoreService = game:GetService("DataStoreService")
local PropertyData = DataStoreService:GetDataStore("Properties")

local Player = game:GetService("Players”).LocalPlayer

local PartProperties = {
    "BrickColor", "Material", "Name"
}

local Part = workspace.Part

function GetPartProperties(Part)
    if not (Part) then return end
    local Properties = {}
    for _,Property in pairs(PartProperties) do
        Properties[Property] = Part[Property]
    end
    return Properties
end

PropertyData:SetAsync(Player.UserId.."Properties", GetPartProperties(Part))

This is not the full answer, this does most of the lifting either way. The rest of the code is left to you to try!

This discussion is preserved as it was. New answers, comments, and votes are closed.