function module.SaveLoad_Placement(Load_Placement:boolean, PlacementName:string, cframe:CFrame, Remove:boolean)
local Profile = module.Profiles[PlayerSaved]
--- Repeats until Profile is set and loaded
while not Profile do
wait(1)
Profile = module.Profiles[PlayerSaved]
end
--- Service
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--- Folder
local PlacedObjects = workspace.PlayerHome_World:WaitForChild("PlacedObjects")
--- Function
if PlacementName and cframe and not Remove then -- if PlacementName is provided with Position and Orientation then create table to save placement
-- assigns name of placement and CFrame such pos on all axis and all orientaitons
print("Before Table", cframe)
local TableTemplate = {Name = PlacementName, cFrame = {cframe:GetComponents()}}
local SavedTable, Result = pcall(function() -- pcall
table.insert(Profile.Data.Placement, TableTemplate)
print("After Table", TableTemplate.cFrame)
end)
if not SavedTable then -- if table failed to save
warn("Error, Couldn't Save Placement Table:", Result)
else -- if successful
print("Successfully Saved Placement:", PlacementName)
end
return
end
--------------------------------
if PlacementName and cframe and Remove then
-- Pre set variable
local Table_Index_To_Remove
-- For loop to find table
for i, StoredPlacement in pairs(Profile.Data.Placement) do -- loops through Player database "Placement"
if StoredPlacement.cFrame.Pos then -- If Playerr Saved Placement Has Old Method Of Cframe Saving
if StoredPlacement.Name == PlacementName then -- if the looped table has same PlacementName
Table_Index_To_Remove = i -- store the index
break
end
else -- If Player Saved Placement Has New Serialized Method Of Cframe Saving
if cframe then
local cframe = {cframe:GetComponents()}
print("Got", cframe, "Saved", StoredPlacement.cFrame)
for _, StoredPlacement_CFrame in StoredPlacement.cFrame do
for _, got_cframe in cframe do
if StoredPlacement_CFrame == got_cframe then
print("Match", StoredPlacement_CFrame, got_cframe)
end
end
end
end
end
end
if Table_Index_To_Remove then -- if table index to remove is found
local TableRemoved, Result = pcall(function() -- Pcall
print("Removing Index",Table_Index_To_Remove)
table.remove(Profile.Data.Placement, Table_Index_To_Remove)
end)
if not TableRemoved then -- if table failed to remove
warn("Error, While Removing Placement Table:", Result) -- prints error
else -- Table Removed successfully
print("Successfully Removed Table:", PlacementName) -- print warn
end
else -- if table was not found
warn("Attempt To Remove Table Failed, Table Was Not Found:", PlacementName)
end
return
end
----------------------
if Load_Placement then
for i, StoredPlacement in pairs(Profile.Data.Placement) do
-- Placement Remover, Devs Can Remove Placements From Player DataStore Before Script Loads In, Using "Placements_To_Remove"
if StoredPlacement and table.find(Placements_To_Remove, StoredPlacement.Name) then
table.remove(Profile.Data.Placement, table.find(Profile.Data.Placement, StoredPlacement))
continue
end
---
local Found_Placement = ReplicatedStorage["Models/Parts"]:WaitForChild("Furniture"):FindFirstChild(StoredPlacement.Name, true):Clone()
if not Found_Placement then -- Bug ProVision
warn(StoredPlacement, "Was Not Found In Furniture")
for Repeat = 1, 2 do -- repeats 2 times to find placement before it gives up on it
wait(1)
Found_Placement = ReplicatedStorage["Models/Parts"]:WaitForChild("Furniture"):FindFirstChild(StoredPlacement.Name, true):Clone()
end
continue -- skips to next StoredPlacement if not found
end
if Found_Placement.PrimaryPart then print("Found Placement Has PrimaryPart")
if StoredPlacement.cFrame.Pos then -- If Player Has A Placement With Old Position And Orientation Saving Method Then It Does A Diff Load
local Pos = StoredPlacement.cFrame.Pos
local Ori = StoredPlacement.cFrame.Ori
Found_Placement:SetPrimaryPartCFrame(CFrame.new(Pos.posX, Pos.posY, Pos.posZ) * CFrame.Angles(math.rad(Ori.oriX), math.rad(Ori.oriY), math.rad(Ori.oriZ)))
else -- If Player Placement Has New Serialization Method Then Load
print("Saved CFrame", StoredPlacement.cFrame)
Found_Placement:SetPrimaryPartCFrame(CFrame.new(table.unpack(StoredPlacement.cFrame)))
print("Set CFrame", Found_Placement.PrimaryPart.CFrame)
end
Found_Placement.Parent = PlacedObjects
else
warn(Found_Placement, "Has No PrimaryPart")
continue -- if no primary part found then continue to next placement
end
end
end
end
Yes Because I can’t proceed to remove the table if I cannot match the CFrame with the one that the player wants to remove, or other wise I will remove a random one.