Hey everyone! So I made an onJoin local function which also contains the function for when a child is added.
The pcall is throwing the error of “Failed to cast value to function” while in attempt to datastore a table.
I am using UpdateAsync()
, so I don’t really know if that is affecting it?
Anyway, my code is below, and if anyone knows the issue, please tell me! Thanks!
if Data then
if type(Data) == "string" then
local gun = Data
local sv = Instance.new("StringValue")
sv.Name = gun
sv.Parent = plr:WaitForChild("OwnedGuns")
updateOwned:FireClient(plr, sv.Name)
elseif type(Data) == "table" then
for i, gun in pairs(Data) do
local sv = Instance.new("StringValue")
sv.Name = gun
sv.Parent = plr:WaitForChild("OwnedGuns")
updateOwned:FireClient(plr, sv.Name)
end
end
else
warn("New player or data corrupted")
local sv = Instance.new("StringValue")
sv.Name = "AK47U"
sv.Parent = plr:WaitForChild("OwnedWeapons")
updateOwned:FireClient(plr, "AK47U")
end
wait()
plr:WaitForChild("OwnedGuns").ChildAdded:Connect(function(child)
local suc, err = pcall(function()
Owned:UpdateAsync(plr.UserId, child.Name)
end)
if not suc then
print(err)
else
print("Success!")
end
end)```