Ad
Log in to vote
0

How to create an string that represents an instance?

Asked by 1 year ago

Im creating an rpg that uses datastore and since you can't save instances directly how would I create a string that represents an instance?

0
All you need to do is put the instance in ServerStorage, then clone it if the string that was saved is the correct one. Perci1 4857 — 1y

1 answer

Log in to vote
0
Answered by
P100D 480
1 year ago
Edited 1 year ago

Assuming you don't have to have instances that are too complex, you could just save an instance with its properties in a table, or even just the name of an instance.

Example:

--Structure: name = {className, parent, transparency, anchored, CanCollide, Size, CFrame)
items = {
    "Name1" = {
        "Part", 
        workspace,
        0.5,
        true,
        false,
        Vector3.new(5, 4, 2),
        CFrame.new(0,1,0)
    },
    "Name2" = {
        "Part",
        workspace,
        0.5,
        true,
        false,
        Vector3.new(7, 2, 1),
        CFrame.new(2,5,1)
    }
}

Then just load the instances by iterating through them:

for name, tbl in pairs(items) do
    newItem = Instance.New(tbl[1], tbl[2])
    newItem.Transparency = tbl[3]
    newItem.Anchored = tbl[4]
    newItem.CanCollide = tbl[5]
    newItem.Size = tbl[6]
    newItem.CFrame = tbl[7]
end

If your instance can have only one set of preset properties, just put it in a folder in ServerStorage. Save the name of the instance and then just clone it from ServerStorage when required.

0
This would be helpful if I was using smaller instances. The instances that I'm planning to save are complex weapon/item models with many unions and parts. Is there another way to do this for more complex items? Or would I have to use this method. dustyripjaw 2 — 1y
Ad

Answer this question



Ad