So, for the past few weeks, I’ve been working on a building system w/ saving, however, I’ve had issues with saving the furniture inventory from the beginning, alright. I’ve decided to try to fix it myself, a few weeks later, I unfortunately still wasn’t able to fix it, so here I am. Thank you everybody in advance.
Function to buy the furniture
print("bought and added")
local Furniture = {playerData:GetAsync(player.UserId.."-Furniture")}
table.insert(Furniture, furnitureName)
local FurJSON = game:GetService("HttpService"):JSONEncode(Furniture)
local success, errormessage = pcall(function()
playerData:SetAsync(player.UserId.."-Furniture", FurJSON)
end)
if success then
print("Data successfully saved!")
else
print("There was an error while saving the data")
warn(errormessage)
end
Function to send the furniture
print("sending")
wait(4)
game.ReplicatedStorage.Remotes.LoadFurniture:FireClient(player, playerData:GetAsync(player.UserId.."-Furniture"))
return playerData:GetAsync(player.UserId.."-Furniture")
Placing function:
local Furniture = playerData:GetAsync(player.UserId.."-Furniture")
local FurJSON = game:GetService("HttpService"):JSONDecode(Furniture)
for i, v in pairs(FurJSON) do
if furnitureName == v then
table.remove(FurJSON, i)
break
end
end
local New = game:GetService("HttpService"):JSONEncode(FurJSON)
local success, errormessage = pcall(function()
playerData:SetAsync(player.UserId.."-Furniture", New)
end)
if success then
print("Data successfully saved!")
else
print("There was an error while saving the data")
warn(errormessage)
end
game.ReplicatedStorage.Remotes.LoadFurniture:FireClient(player, playerData:GetAsync(player.UserId.."-Furniture"))
The function which is used to get the furniture, local:
print("GotData")
local ActualF = {Furniture}
local t = {}
for i, x in pairs(ActualF) do
table.insert(t, x)
end
print(t)
for i, x in pairs(script.Parent.Building.Furniture:GetChildren()) do
if x.ClassName ~= "UIGridLayout" then
x:Destroy()
end
end
for i, x in pairs(game.ReplicatedStorage.Furniture:GetChildren()) do
for i, xx in ipairs(t) do
--for index = 1, #Furniture do
--local xx = Furniture[index]
print("man")
if x.Name == xx then
print("Match found")
local Frame = script.Parent.Building.FurniturePiece:Clone()
Frame.Parent = script.Parent.Building.Furniture
Frame.Visible = true
x:Clone().Parent = Frame.ViewportFrame
Frame.FurnitureName.Value = x.Name
end
end
end;