How would i save/load parts shape to datastore?

Im trying to save parts shape to datastore and later load it, problem is that when i save parts shape as

Shape = tostring(v.Shape)

it saves as “Enum.PartType.Block”, And when loading it gives this error - Enum.PartType.Block is not a valid member of “Enum.PartType”

any help would be appreciated :slight_smile:

Save the string rather than the Enum, so for Example if you have Enum.PartType.Block, just save the word Block as a string into the DataStore, and when you want to access it, you can do this:

local str = "Block" -- The Name to access the Enum.PartType value
print(Enum.PartType[str]) -- this should give you the Enum if you do it correctly.

Im not sure if you can easily do this however, so you may need to use tables to access the word.

(Im pretty sure I meant to say index, but whatever)

You have to cut out the Enum.PartType. string part from your original string. You could do it like so:

Shape = Shape:sub(15, -1)
-- 15 being the start of the shape
-- -1 being the end of the string

Another way would be by splitting the string. Every time you see a . and then getting the last value (which is always 3 for Enums.)

Shape = Shape:split(".")[3]
-- split returns an array of each value splitted by a "."
-- {"Enum", "PartType", "Block"}

If either self:split(...) or self:sub(...) do not work instead use string.split(self, ...) and string.sub(self, ...)

Or use EnumType.Name like a Normal Person.

print(Enum.PartType.Block.Name) -- "Block"

So you dont even need to do all that to get the Name

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