Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Inventory Save System [NOT SAVING/LOADING?]

The title explains the issue but I dont know whats wrong because it saves(i think) but its not loading!

HERES THE SCRIPT!

local invData = game:GetService("DataStoreService"):GetDataStore("invTest")

  

game.Players.PlayerAdded:Connect(function(player)

local Key = "Player-ID"..player.UserId

local Data = invData:GetAsync(Key)

local Inv = Instance.new("Folder", player)

Inv.Name = "Inventory"

if Data ~= nil then

for i,v in pairs(Data) do

local itemBool = Instance.new("BoolValue", Inv)

itemBool.Name = v.Name

itemBool.Value = true

end

end

end)

  

game.Players.PlayerRemoving:Connect(function(player)

local Key = "Player-ID"..player.UserId

local Inv = player.Inventory:GetChildren()

local InvToSave = {}

for i,v in pairs(Inv) do

table.insert(InvToSave, v.Name)

end

if InvToSave ~= nil then

invData:SetAsync(Key, InvToSave)

end

end)

2 answers

✓ Accepted answer

I assume you testing this in studio. The problem is to access the API services you have to enable studio access to API in settings. It should work in game. Hope this helps. Please tell me if it doesn't

This discussion is preserved as it was. New answers, comments, and votes are closed.