is that correct?
local players = game:GetService("Players")
local dataStoreService = game:GetService("DataStoreService")
local autoSavingStore = dataStoreService:GetDataStore("F3XAutoSave")
local keyPrefix = "Player: "
local function save(player: Player)
local key = keyPrefix .. tostring(player.UserId)
local data = {}
for i, obj: BasePart in ipairs(workspace:FindFirstChild("Builds"):WaitForChild(player.Name):GetDescendants()) do
if obj:IsA("BasePart") then
table.insert(data, {
-- PART PROPERTIES
obj.Name,
obj.CanCollide,
obj.Position.X,
obj.Position.Y,
obj.Position.Z,
obj.Orientation.X,
obj.Orientation.Y,
obj.Orientation.Z,
obj.Anchored,
obj.Size.X,
obj.Size.Y,
obj.Size.Z,
obj.Color.R,
obj.Color.G,
obj.Color.B,
(string.match(tostring(workspace.Baseplate.TopSurface), "%.(%w+)$")),
(string.match(tostring(workspace.Baseplate.BottomSurface), "%.(%w+)$")),
(string.match(tostring(workspace.Baseplate.LeftSurface), "%.(%w+)$")),
(string.match(tostring(workspace.Baseplate.RightSurface), "%.(%w+)$")),
(string.match(tostring(workspace.Baseplate.BackSurface), "%.(%w+)$")),
(string.match(tostring(workspace.Baseplate.FrontSurface), "%.(%w+)$")),
obj.Transparency,
obj.Reflectance,
string.match(tostring(obj.Material), "%.(%w+)$")
})
local success, err
repeat
success, err = pcall(function()
autoSavingStore:SetAsync(key, function()
return game:GetService("HttpService"):JSONEncode(data)
end)
end)
task.wait()
until success
end
end
end
local function load(player: Player)
local key = keyPrefix .. tostring(player.UserId)
local success, err
local data
repeat
success,err = pcall(function()
data = autoSavingStore:GetAsync(key)
end)
until success or not players:FindFirstChild(player.Name)
if not data then return end
if success then
data = game:GetService("HttpService"):JSONDecode(data)
for i, obj in ipairs(data) do
local partInstance = Instance.new("Part")
partInstance.Name=obj[1]
partInstance.CanCollide=obj[2]
partInstance.Position = Vector3.new(obj[3], obj[4], obj[5])
partInstance.CFrame *= CFrame.Angles(math.rad(obj[6]),math.rad(obj[7]),math.rad(obj[8]))
partInstance.Anchored=obj[9]
partInstance.Size = Vector3.new(obj[10], obj[11], obj[12])
partInstance.Color = Color3.new(obj[13],obj[14],obj[15])
partInstance.TopSurface = Enum.SurfaceType[obj[16]]
partInstance.BottomSurface = Enum.SurfaceType[obj[17]]
partInstance.LeftSurface = Enum.SurfaceType[obj[18]]
partInstance.RightSurface = Enum.SurfaceType[obj[19]]
partInstance.BackSurface = Enum.SurfaceType[obj[20]]
partInstance.FrontSurface = Enum.SurfaceType[obj[21]]
partInstance.Transparency = obj[22]
partInstance.Reflectance = obj[23]
partInstance.Material = Enum.Material[obj[24]]
end
else
warn(tostring(err))
end
end
players.PlayerAdded:Connect(load)
players.PlayerRemoving:Connect(save)
game:BindToClose(function()
for i, plr: Player in ipairs(players:GetPlayers()) do
save(plr)
end
end)