Ad
Log in to vote
0

How to create an string that represents an instance?

Asked by 9 months 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 4838 — 9mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by
P100D 480
9 months ago
Edited 9 months 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 — 9mo
Ad

Answer this question



Ad