#A Inventory saving data not working for some reason

48 messages · Page 1 of 1 (latest)

worldly shard
#

no errors

#

in output

visual spruce
#

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

worldly shard
visual spruce
#

local Char = plr.Character or plr.CharacterAdded:Wait() you mean?

visual spruce
#

won't work

#

it won't fire everytime the character loads

worldly shard
#

how should i do it then?

visual spruce
#
 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

worldly shard
#

ok ill replace it

cinder steepleBOT
#

studio** You are now Level 3! **studio

visual spruce
#

didn't work?

worldly shard
visual spruce
#
 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

worldly shard
#

did not work

visual spruce
#

try to reset after spawning in

worldly shard
#

i think the problem is not the character

arctic bloom
#

startergear?

#

what is that

#

tbh, i know it exists

#

but what its his purpose

surreal scarab
surreal scarab
#

I’ll try to recreate the problem when I get home (3-3:30PM EST)

surreal scarab
#

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)```
cinder steepleBOT
#

studio** You are now Level 3! **studio

surreal scarab
#

@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 coolguy

#

I've also made it check if the "Child" was a tool before saving so it doesn't include body parts