So i made a article on this yesterday about saving the build. It worked (thanks guys!). But, there is a big flaw when the DataStore saves the data. It makes all the values I want to save in to one? So that means I can't load the build without it having a error because of the Position value I saved since it add the values up. How can I make the dictionary of values not turn in to one value? Here are the links to the scripts I have:
Save Script: https://pastebin.com/Y2W3kckk
01 | game.ReplicatedStorage.SaveBuild.OnServerEvent:Connect( function (player) |
02 | local partTable = { } |
03 |
04 | for i, inst in pairs (workspace:GetChildren()) do |
05 | if inst.Name = = "BuiltBlock" then |
06 | local position = { |
07 | X = inst.Position.X, |
08 | Y = inst.Position.Y, |
09 | Z = inst.Position.Z |
10 |
11 | } |
12 | local material = inst.Material |
13 | local color = inst.BrickColor |
14 | local size = inst.Size |
15 | partTable [ i ] = { Position = position, Material = tostring (material), Color = tostring (color), Size = tostring (size) } |
Load Script:
01 | game.ReplicatedStorage.LoadBuild.OnServerEvent:Connect( function (player) |
02 | local s,e = pcall ( function () |
03 | local build = BuildsDataStore:GetAsync(player.UserId) |
04 | for i, tab in pairs (build) do |
05 | local block = Instance.new( "Part" ,workspace) |
06 | block.Name = "BuiltBlock" |
07 | block.Position.X = tonumber (tab.Position.X) |
08 | block.Position.Y = tonumber (tab.Position.Y) |
09 | block.Position.Z = tonumber (tab.Position.Z) |
10 | block.Size = tonumber (tab.Size) |
11 | block.Material = tab.Material |
12 | block.BrickColor = tab.Color |
13 | end |
14 | end ) |
15 | if s then |
16 | print ( "Successfully loaded build!" ) |
17 | elseif not s and e then |
18 | print ( "Not successful: " ..e) |
19 | end |
20 | end ) |
Error when loaded: Not successful: X cannot be assigned to
Data that was saved in the block tables: https://i.imgur.com/WdY9wr1.png
Please answer my question!! -- DragonSpawner12 :D
Vector3.X/Y/Z are read-only properties, you may not mutate vectors, only create new ones. Instead a new vector should be made with the X/Y/Z coordinates being assigned using the appropriate constructor Vector3.new(X ,Y, Z) (in your case block.Position
is the vector, you'd do block.Position = Vector3.new(X ,Y, Z)
)
Also, you don't need to (re)convert the coordinates to numbers at all! Types do not change while saving/retrieving, tab.Position.X/Y/Z
will be a number since it's saved as one.
Another thing I noticed is that you're wrongly assuming BasePart.Size to be a single number, while it is in fact a Vector3 type similar to BasePart.Position, you'll have to implement the same method you did with position.