Hello, Im trying to make a datastore for the guns the player owns.
local DSS = game:GetService("DataStoreService")
local GunDataStore = DSS:GetDataStore("GunSave")
local function saveData(plr)
if plr:FindFirstChild("Guns")then
local OwnedGuns = {}
for i, v in pairs(OwnedGuns) do
if v.Value == true then
table.insert(OwnedGuns, v.Name)
end
end
for i, v in pairs(OwnedGuns) do
print(tostring(v))
end
local success, err = pcall(function()
GunDataStore:SetAsync(plr.UserId, OwnedGuns)
end)
if success then
print("Data Saved")
else
print("Data not saved")
end
end
end
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
saveData(v)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
saveData(plr)
end)
This is the script I am using. When I do the loop that prints everything in the table, nothing prints even though a gun name should print.