I have a script that saves the properties of blocks and models placed:
-- Save BLOCKS---
local InfoToSave = {}
for _,BA in pairs(bases:GetChildren()) do
if BA:FindFirstChild("Owner").Value == player.UserId then
local FolderToSave = BA:FindFirstChild("Blocks")
local BaseCFrame = BA:FindFirstChild("Base").CFrame
for _, b in pairs(FolderToSave:GetChildren()) do
if b.ClassName == "Part" then
local PartInfo = {
["Position"] = {X = b.CFrame:toObjectSpace(BaseCFrame).x, Y = b.CFrame:toObjectSpace(BaseCFrame).y, Z = b.CFrame:toObjectSpace(BaseCFrame).z};
["Color"] = {R = b.Color.r, G = b.Color.g, B = b.Color.b};
["OldBaseName"] = {N = tostring(BA.Name)};
["Transparency"] = {T = tonumber(b.Transparency)};
["Material"] = b.Material.Value;
--["Rotation"] = {X = b.Orientation.x, Y = b.Orientation.y, Z = b.Orientation.z };
}
table.insert(InfoToSave, PartInfo)
print(b.Name)
end
end
break
end
end
dataStore:SetAsync(player.UserId .. "_blocks", InfoToSave)
-- END OF SAVE BLOCKS
--MODELS SAVE
local InfoSave = {}
for i,v in pairs (bases:GetChildren()) do
if v:FindFirstChild("Owner").Value == player.UserId then
local FolderToSave = v:FindFirstChild("Blocks")
[ 10:39 PM ]
local BaseCFrame = v:FindFirstChild("Base").CFrame
for _, m in pairs(FolderToSave:GetChildren()) do
if m.ClassName == "Model" then
local ModelInfo = {
["Name"] = m.Name;
["Position"] = {X = m.Base.CFrame:toObjectSpace(BaseCFrame).x, Y = m.Base.CFrame:toObjectSpace(BaseCFrame).y, Z = m.Base.CFrame:toObjectSpace(BaseCFrame).z};
["OldBaseName"] = {N = tostring(v.Name)};
}
table.insert(InfoSave, ModelInfo)
print(ModelInfo["Name"])
end
end
break
end
end
dataStore:SetAsync(player.UserId .. "_models", InfoSave)
--END OF MODEL SAVES
This script loads them when the player rejoins.
--LOAD BLOCKS--
local data = nil
local good, info = pcall(function()
data = dataStore:GetAsync(player.UserId .. "_blocks")
end)
if good and data then
for _,v in pairs(bases:GetChildren()) do
if v:FindFirstChild("Owner").Value == player.UserId then
local PlayerBase = v:WaitForChild("Blocks")
for index, tabl in pairs(data) do
local CFRameOldB = game.Workspace:WaitForChild("Bases"):WaitForChild(tabl["OldBaseName"]["N"]):WaitForChild("Base").CFrame
local partsOldPosition = CFrame.new(tabl["Position"]["X"],tabl["Position"]["Y"], tabl["Position"]["Z"])
local newBase = v:FindFirstChild("Base")
local NewPart = Instance.new("Part")
NewPart.Parent = PlayerBase
NewPart.Size = Vector3.new(3,3,3)
NewPart.CFrame = partsOldPosition:toObjectSpace(newBase.CFrame)
NewPart.Material = tabl["Material"]
NewPart.Color = Color3.new(tabl["Color"]["R"],tabl["Color"]["G"], tabl["Color"]["B"])
--NewPart.Orientation = Vector3.new(tabl["Rotation"]["X"], tabl["Rotation"]["Y"], tabl["Rotation"]["Z"])
NewPart.BackSurface = "Smooth"
NewPart.BottomSurface = "Smooth"
NewPart.FrontSurface = "Smooth"
NewPart.LeftSurface = "Smooth"
NewPart.RightSurface = "Smooth"
NewPart.TopSurface = "Smooth"
NewPart.Transparency = (tabl["Transparency"]["T"])
NewPart.Anchored = true
NewPart.CFrame = partsOldPosition:toObjectSpace(newBase.CFrame)
wait(.7)
end
break
end
end
else
print("UNABLE TO [PARTS]", info)
end
---END OF LOAD BLOCKS--
--LOAD MODELS--
local data = nil
local good, info = pcall(function()
data = dataStore:GetAsync(player.UserId .. "_models")
end)
if good and data then
for _, v in pairs(bases:GetChildren()) do
if v:FindFirstChild("Owner").Value == player.UserId then
local PlayerBase = v:WaitForChild("Blocks")
for index, tabl in pairs(data) do
local CFRameOldB = game.Workspace:WaitForChild("Bases"):WaitForChild(tabl["OldBaseName"]["N"]):WaitForChild("Base").CFrame
local partsOldPosition = CFrame.new(tabl["Position"]["X"],tabl["Position"]["Y"], tabl["Position"]["Z"])
local newBase = v:FindFirstChild("Base")
local FurnItems = game:GetService("ReplicatedStorage"):WaitForChild("GameItems"):WaitForChild("Furniture"):GetChildren()
for i,item in pairs(FurnItems) do
if item.Name == (tabl["Name"]) then
local itemC = item:Clone()
itemC.Parent = PlayerBase
itemC:SetPrimaryPartCFrame(partsOldPosition:toObjectSpace(newBase.CFrame))
wait(.7)
end
end --For item loop end
--break
end
end
end
else
print("UNABLE TO [MODELS]", info)
end
--END OF LOAD MODELS--
I placed stairs and blocks in this pictures, the stairs are a single model, placed next to eachother to make them appear bigger. https://gyazo.com/cb8690a213b0ba77190fded813ee2cfc
And when I rejoined the stairs loaded away from where they should’ve loaded at https://gyazo.com/737e6e0f071a819751eeb4356f1ad29f
The reason I’m using CFrame is because the player is assigned different bases to build on each time they join, so I have to use toObjectSpace to have it placed in the same position it was on the last base.