I am making a save slot system and I got everything to work, but I am having trouble figuring out how to save the binds of wireable objects. I tried making every block have a block id and it would check through all those block ids to see if it is the right one, but that didn’t work.
Save slots script:
--local DataStore = game:GetService("DataStoreService")
--local SaveSlotsDataStore = DataStore:GetDataStore("SaveSlots")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder", player)
folder.Name = "Save Slots"
end)
game.ReplicatedStorage.Events.Server.Save.OnServerEvent:Connect(function(player, saveSlot)
local slots = player:WaitForChild("Save Slots")
local folder
if slots:FindFirstChild(saveSlot) then
slots:FindFirstChild(saveSlot):ClearAllChildren()
folder = slots:FindFirstChild(saveSlot)
else
folder = Instance.new("Folder", slots)
folder.Name = saveSlot
end
if folder then
for _, v in pairs(workspace.Blocks:GetChildren()) do
if v.owner.Value == player.UserId then
local Folder = Instance.new("Folder", folder)
Folder.Name = v.Name
for _, b in pairs(v:GetChildren()) do
if b.Name == "Settings" then
local settingsFolder = Instance.new("Folder", Folder)
settingsFolder.Name = "Settings"
for _, c in pairs(b:GetChildren()) do
c:Clone().Parent = settingsFolder
end
end
if b.Name == "blockId" then
b:Clone().Parent = Folder
end
local blockId
if b.Name == "inputObj" then
blockId = b.Value.blockId:Clone()
blockId.Name = "inputObj"
for _, c in pairs(workspace.Blocks:GetChildren()) do
if c == b.Value then
if c:FindFirstChild("blockId") then
for _, v in pairs(folder:GetChildren()) do
if v:FindFirstChild("blockId") then
print(v.blockId.Value)
print(c.blockId.Value)
if v.blockId.Value == c.blockId.Value then --This doesn't work
print("true")
blockId.Parent = v
end
end
end
end
end
end
end
end
local plot = workspace.Plots:FindFirstChild(player.Team.Name)
local Cframe = Instance.new("CFrameValue", Folder)
Cframe.Name = "Cframe"
Cframe.Value = plot.Plot.CFrame:ToObjectSpace(v.WorldPivot)
end
end
end
game.ReplicatedStorage.Events.Server.Save:FireClient(player)
end)
game.ReplicatedStorage.Events.Server.Load.OnServerEvent:Connect(function(player, saveSlot)
if player:WaitForChild("Save Slots"):FindFirstChild(saveSlot) then
for _, v in pairs(workspace.Blocks:GetChildren()) do
if v.owner.Value == player.UserId then
v:Destroy()
end
end
local slot = player["Save Slots"]:FindFirstChild(saveSlot)
for _, block in pairs(slot:GetChildren()) do
if game.ReplicatedStorage.Blocks:FindFirstChild(block.Name) then
wait(0.05)
local Block = game.ReplicatedStorage.Blocks:FindFirstChild(block.Name):Clone()
Block:Clone()
Block:PivotTo(workspace.Plots:FindFirstChild(player.Team.Name).Plot.CFrame:ToWorldSpace(block.Cframe.Value))
local owner = Instance.new("IntValue", Block)
owner.Name = "owner"
owner.Value = player.UserId
local weldPart = Instance.new("Part", Block)
weldPart.Name = "WeldPart"
weldPart.Size = Vector3.new(Block.Root.Size.X+0.05,Block.Root.Size.Y+0.05,Block.Root.Size.Z+0.05)
weldPart.Anchored = true
weldPart.Position = Block.Root.Position
weldPart.CanCollide = true
weldPart.Transparency = 0.5
local touchingParts = weldPart:GetTouchingParts()
for _, part in pairs(touchingParts) do
if part.Parent:FindFirstChild("Humanoid") then
--
else
local weld = Instance.new("WeldConstraint", Block.Root)
weld.Part0 = Block.Root
weld.Part1 = part
end
end
weldPart:Destroy()
for _, v in pairs(block.Settings:GetChildren()) do
wait(0.1)
Block.Settings:FindFirstChild(v.Name).Value = v.Value
end
Block.Parent = workspace.Blocks
end
end
end
end)
If anyone can please help me with this since I have been trying to do this for days at this point.