Help, this is the script where I supposedly did a door save (which is destroyed if you knock with a “Destroy()” block), but apparently I don’t get saved and I don’t think my scripts are that good. I need your help
Script (DataStore) “ServerScriptService”
local ds = game:GetService("DataStoreService"):GetDataStore("PortalesSave")
game.Players.PlayerAdded:connect(function(plr)
local key = "id-"..plr.userId
pcall(function()
local PortalesGuardar = ds:GetAsync(key)
if PortalesGuardar then
for i,v in pairs(PortalesGuardar)do
local PortalesGuardar = game.ServerStorage.PortalesGuardar:FindFirstChild(v)
if PortalesGuardar then
PortalesGuardar:Clone().Parent = plr:WaitForChild("Backpack")
PortalesGuardar:Clone().Parent = plr:WaitForChild("StarterGear")
end
end
end
end)
end)
game.Players.PlayerRemoving:connect(function(plr)
local key = "id-"..plr.userId
pcall(function()
local PortalesGuardarToSave = {}
for i,v in pairs(plr.Backpack:GetChildren())do
if v then
table.insert(PortalesGuardarToSave,v.Name)
end
end
ds:SetAsync(key,PortalesGuardarToSave)
end)
end)
local ds = game:GetService("DataStoreService"):GetDataStore("PortalesSave")
game.Players.PlayerAdded:connect(function(plr)
local key = "id_"..plr.userId
pcall(function()
local PortalesGuardar = ds:GetAsync(key)
if PortalesGuardar then
for i,v in pairs(PortalesGuardar)do
local PortalesGuardar = game.ServerStorage.PortalesGuardar:FindFirstChild(v)
if PortalesGuardar then
PortalesGuardar:Clone().Parent = plr:WaitForChild("Backpack")
PortalesGuardar:Clone().Parent = plr:WaitForChild("StarterGear")
end
end
end
end)
end)
game.Players.PlayerRemoving:connect(function(plr)
local key = "id_"..plr.userId
pcall(function()
local PortalesGuardarToSave = {}
for i,v in pairs(plr.Backpack:GetChildren())do
if i then
table.insert(PortalesGuardarToSave,i.Name)
end
end
ds:SetAsync(key,PortalesGuardarToSave)
end)
end)
Why on earth would you want to check if the index is present? That’s always going to be the case. The same argument could be made for v tbh. And why is changing the separator to an underscore going to change it? I don’t see how saying “oof magic, here’s some changes” without explaining is helpful?
@JuanesLolgamer I can’t see anything immediately wrong. I would recommend using the debugger and stepping through the code, inspect the values in the table once the player has removed (just use the command line to kick yourself to trigger in in studio), then do the same for loading. This should hopefully tell you what data isn’t correct and you can use that to work out a solution.
e.g. place a debug point on the following line, hover over the variable and check what’s in the ‘PortalesGuardarToSave’ table ds:SetAsync(key,PortalesGuardarToSave)
and then again on the line it loads from. local PortalesGuardar = ds:GetAsync(key)