For the past week (and now hour due to no responses to my previous question) I have attempted to remake my datastore script and improve it. The remote events work fine and so do the purchases - however, I keep getting the same error on my loading script where it says bag argument #1: table expected, got nil. Any help would be appreciated, I'm really stuck on this one.
code inside of a server script:
local success, errormessage = pcall(function()
local piratedata = pirate:GetAsync(tostring(player.UserId.."-inventory"))
return piratedata
end)
if success then
print("success loading data")
if piratedata == nil then
piratedata = "nun"
end
print(piratedata)
local tbl = {}
tbl = table.insert(tbl,1,piratedata)
local Piratepurchased = Instance.new("BoolValue",player)
Piratepurchased.Name = "Pirate"
for i,value in pairs (tbl) do --this is the line that throws the error
if value == "pirate" then
print("it was yes")
local pirateclone = game.ReplicatedStorage:WaitForChild("Gears").GrogGlass:Clone()
pirateclone.Parent = player.StarterGear
pirateclone.Parent = player.Backpack
Piratepurchased = true
break
else
Piratepurchased = false
wait()
end
end
else
print("Error getting data")
warn(errormessage)
end
end)
:)
