It would be helpful if you could post the entire block of code that begins with:
if plr and plr.Parent then
I would also recommend adding more logs to that block of code so that you can see exactly which conditions are being met. It does seem unlikely that game:GetService("BadgeService"):UserHasBadgeAsync(plr.UserId,id)
would evaluate to true
if the player does not have the badge, even given Roblox’s service outage.
You shouldn’t seek to use pcall()
as a means to fix errors, if that’s what you mean. pcall()
should be used to handle errors that you know to expect and have a solution for. Using pcall()
to simply hide errors can lead to further unexpected behavior. In the case of the Roblox issue I linked above, using pcall()
would hide the error, but not fix the behavior of the part of the program that implements it, as Roblox’s service would still be throwing an error. You just wouldn’t see it.
I don’t see any response from Roblox telling us that it has been resolved, so I’d assume so.
By the way, not to get too off topic or nitpicky, but…
if plr.Badges:FindFirstChild(id) then else
This “if then else
” approach for the first condition is a pretty unconventional and ill-advised coding pattern. Your code would be more readable if you simply used
if player.Badges:FindFirstChild(id) == false then
or even
if not plr.Badges:FindFirstChild(id) then
While the “if then else
” pattern might look like it makes some sense in Lua, in just about any other language it would have to look like this:
if (plr.Badges:FindFirstChild(id)) {} else {}
which doesn’t really make any sense. It also makes it more difficult to later add a real “else” condition.