I’m making an inventory save, but there is a problem. It saves but usually doesn’t notify me that it saves and doesn’t tell me that it got the saved items and doesn’t give them either when the player rejoins. When i type in the console to loop through the datastore it finds the items! It just won’t give them! Any help? Here is my code.
local ds = game:GetService("DataStoreService"):GetDataStore("Weapons")
game.Players.PlayerAdded:Connect(function(p)
print("Player added!")
local success,response
local data
local count = 0
repeat
if count >= 1 then
print("Retrying, count:", count, "\nError:", response)
wait(5)
end
success,response = pcall(function()
count = count + 1
ds:GetAsync(p.UserId)
end)
until success
print(success)
for i,v in pairs(data) do
print("Player has data!")
if game.ReplicatedStorage.Weapons:FindFirstChild(v) then
print("Found tool!")
game.ReplicatedStorage.Weapons[v]:Clone().Parent = p.Backpack
print("Gave player tools!")
end
end
end)
game.Players.PlayerRemoving:Connect(function(p)
local t = {}
local count = 0
local success,response
for i,v in pairs(p.Backpack:GetChildren()) do
if v then
table.insert(t,v.Name)
print("Inserted name!")
end
end
repeat
if count >= 1 then
print("Retrying, count:", count, "\nError:", response)
wait(5)
end
success,response = pcall(function()
count = count + 1
ds:SetAsync(p.UserId,t)
end)
until success
print(success)
if success then
print("Saved weapons!")
end
end)