Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I save properties of an instance with datastore?

Asked by 4 years ago

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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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!

Ad

Answer this question