#A Inventory saving data not working for some reason
48 messages · Page 1 of 1 (latest)
have you tried adding a player.characteradded into the player added
the script will run each time the player character loads in, instead of just once
it is already there tho
local Char = plr.Character or plr.CharacterAdded:Wait() you mean?
how should i do it then?
local DataGot = MainData:GetAsync(plr.UserId)
if DataGot then
for i,Inventory in pairs(DataGot) do
if Folder:FindFirstChild(Inventory) then
local GotData = Folder:FindFirstChild(Inventory):Clone()
GotData.Parent = plr.StarterGear
end
end
end
i think this should work
so you want to add it into startergear instead of backpack
ok ill replace it
** You are now Level 3! **
didn't work?
did not work 😦
yea
local DataGot = MainData:GetAsync(plr.UserId)
if DataGot then
for i,Inventory in pairs(DataGot) do
if Folder:FindFirstChild(Inventory) then
local GotData = Folder:FindFirstChild(Inventory):Clone()
GotData.Parent = plr.StarterGear
end
end
plr:LoadCharacter()
end
try this
whoops
fixed
did not work
try to reset after spawning in
k
i think the problem is not the character
everything inside is supposed to go into the player’s backpack
i did
but it failed
I’ll try to recreate the problem when I get home (3-3:30PM EST)
k ty
Getting character returns nil (without it, the saving part works fine for the backpack only)
Ima try again and I’ll give up if it fails
Woah I might be able to fix it
In 7 mins or so
😮
It works
Ima send script
local MainData = dss:GetDataStore("Inventory")
local Folder = game:GetService("ServerStorage").InvItems
function LoadItems(plr)
local Key = plr.UserId
local Data = MainData:GetAsync(Key)
if Data then
--print(Data)
local backpack = plr.Backpack
for i,v in Data do
if Folder[v] then
Folder[v]:Clone().Parent = backpack
end
end
end
end
function GetEverything(plr)
local SaveTable = {}
local Character = plr.Character or plr.CharacterAdded:Wait()
if Character then
for i,v in Character:GetChildren() do
if v:IsA("Tool") then
table.insert(SaveTable,v.Name)
end
end
end
for i,v in plr.Backpack:GetChildren() do
if v:IsA("Tool") then
table.insert(SaveTable,v.Name)
end
end
return SaveTable
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
LoadItems(plr)
end)
plr.CharacterRemoving:Connect(function()
local Inventory = GetEverything(plr)
MainData:SetAsync(plr.UserId,Inventory)
--print(Inventory)
end)
end)```
** You are now Level 3! **
@worldly shard
sorry for taking 3 hours I forgot about this
I used CharacterRemoving instead of PlayerRemoving so it doesn't define the "Character" variable as nil, as the character would've been removed already 
I've also made it check if the "Child" was a tool before saving so it doesn't include body parts