Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Inventory Save System [NOT SAVING/LOADING?]

Asked by 5 years ago

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

Log in to vote
1
Answered by
HDWC 53
5 years ago

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

Ad
Log in to vote
0
Answered by 5 years ago

change invData to invTest maybe?

Answer this question