13:52:07.737 - ServerScriptService.SavingPlayersWeapons:54: Expected ')' (to close '(' at line 48), got 'inventory_folder'
When I add another parenthesis to the first “end)” success becomes undefined for some reason
Players.PlayerRemoving:Connect(function(client)
print("PlayerLeft")
local key = "client_".. client.UserId
local tools = {}
local inventory_folder = inventories[client.Name]
for _, item in pairs(inventory_folder:GetChildren()) do
table.insert(tools, item.Name)
end
local success, error = pcall(player_data:UpdateAsync(key,function(prev)
if not success then
print(error) -- this print call will only run if success is false
else return tools
end
end)
inventory_folder:Destroy()
end)
print("done")
Players.PlayerRemoving:Connect(function(client)
print("PlayerLeft")
local key = "client_".. client.UserId
local tools = {}
local inventory_folder = inventories[client.Name]
for _, item in pairs(inventory_folder:GetChildren()) do
table.insert(tools, item.Name)
end
local ok, data = pcall(player_data.UpdateAsync, player_data, key, function(prev)
if not ok then
print(error) -- this print call will only run if success is false
else return tools
end
end)
inventory_folder:Destroy()
end)
print("done")
You should get in the habit of formatting your code (you can use a tab or 4 spaces which is the most common indentation level), it helps you debug code easier as you can see which end belongs to which function/statement:
I believe your error is within this block. In the first line , you have 3 opening brackets and you close 2 of them. I think what you need to do is the following:
local success, error = pcall(player_data:UpdateAsync(key,function(prev)) -- added another bracket here
if not success then
print(error) -- this print call will only run if success is false
else return tools
end
end)
But also, I’m not familiar with pcalls so I could be wrong
Looking off of what others are saying, and my experience with pcall, how about you do pcall(function() and just have everything run inside of there instead of having multiple parameters. This will still catch errors and be a lot easier in general.