I’m currently working on an inventory system using profile service and I am not too sure as to what I am doing. I wrote some code and everything works as intended except I keep getting this “assertion failed!” error message from my the second assertion of my :Set function
function PlayerDataHandler:Set(plr, key, value)
local profile = getProfile(plr)
assert(profile.Data[key], string.format("Data does not exist for key: %s", key))
assert(type(profile.Data[key]) == type(value)) --assertion failed?
profile.Data[key] = value
end
It was working perfectly fine yesterday before I tried making an equip and unequip function today.
function PlayerDataHandler:Equip(plr, itemName)
self:Update(plr, "Inventory", function(current)
if table.find(current, itemName) then
table.remove(current, table.find(current, itemName))
self:Update(plr, "Equipped", function(current)
table.insert(current, itemName)
end)
else
print(plr, "does not have", itemName )
end
table.insert(current, itemName)
return current
end)
local item = game.ReplicatedStorage.Assets:FindFirstChild(itemName)
if not item then return end
end
function PlayerDataHandler:Unequip(plr, itemName)
self:Update(plr, "Equipped", function(current)
if table.find(current, itemName) then
table.remove(current, table.find(current, itemName))
self:Update(plr, "Inventory", function(current)
table.insert(current, itemName)
end)
else
print(plr, "does not have", itemName )
end
table.insert(current, itemName)
return current
end)
local item = game.ReplicatedStorage.Assets:FindFirstChild(itemName)
if not item then return end
end
I honestly don’t completely understand what I’m doing with self:Update but the yt video I was following used it so I though it would be better for me to use it. I can barely find any info on assertion failed.
Any help would be greatly appreciated