Hi, I want to save player created parts. I wrote a script, but it doesn’t work and doesn’t give out errors. I don’t need to save models, I just want to create a part from the server with the color, material, and position, save it, and upload it. Can someone help?
Script -
local PartStore = game:GetService("DataStoreService"):GetDataStore("PartStore")
game.Players.PlayerAdded:Connect(function(Player)
local Data = PartStore:GetAsync(Player.UserId)
local NormalData = game:GetService("HttpService"):JSONDecode(Data)
if NormalData then
for k, v in pairs(NormalData) do
local Part = Instance.new("Part")
Part[k] = v
Part.Parent = game.Workspace
end
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
if game.Workspace:FindFirstChild("PlayerBuildings") then
local Tables = {}
for _, v in pairs(game.Workspace.PlayerBuildings:GetChildren()) do
local Save = game:GetService("HttpService"):JSONEncode(v)
print(Save)
table.insert(Tables, Save)
end
local Succes, Error = pcall(function()
PartStore:SetAsync(Player.UserId, Tables)
end)
if Succes then
print("good")
else
warn(Error)
end
end
end)