Badge checker isn't working

if BS:UserHasBadgeAsync(player.UserId, VIPBadge_ID) then
	AccessVIPRoom:FireClient(player)
elseif Tickets.Value >= price then
	Tickets.Value = Tickets.Value - price
	BS:AwardBadge(player.UserId, VIPBadge_ID)
	AccessVIPRoom:FireClient(player)
else
	warn(player.Name.." doesn't have enough Tickets to enter VIP")
end

This script is a VIP room script, and basically checks to see if the player has the badge or not to let them in. If they don’t have the badge, then they pay for it, via price, then get awarded the badge so they don’t need to pay for it again.

This portion of my script has no errors, but every time it runs, (no matter if I have the badge or not) still acts like I’ve never gotten the badge and ends up running the second part of the if statement. (it just takes my money every time)

I have no idea why this is happening…
Any help is appreciated!

2 Likes

Might be something wrong with the if statement order, so try this:

local success, badgeOwned = pcall(BS.UserHasBadgeAsync, BS, player.UserId, VIPBadge_ID)

if success then
	if badgeOwned then
		AccessVIPRoom:FireClient(player)
	else
		if Tickets.Value >= price then
			local success, badgeAwarded = pcall(BS.AwardBadge, BS, player.UserId, VIPBadge_ID)

			if success and badgeAwarded then
				Tickets.Value -= price
				AccessVIPRoom:FireClient(player)
			else
				warn(string.format("Error awarding badge to player %i (%s): %s", player.UserId, player.Name, tostring(badgeAwarded)))
			end
		else
			warn(string.format("Player %i (%s) currently doesn't have enough tickets to enter VIP room", player.UserId, player.Name))
		end
	end
else
	warn(string.format("Error getting badge ownership info for player %i (%s): %s", player.UserId, player.Name, tostring(badgeOwned)))
end
2 Likes

You can check if user have a gamepass in this case

no, pcall returns 2 values.
UserHasBadgeAsync() on its own returns only a single value - whether the user has the badge or not.

1 Like

Can’t see any major issues with that code. Ensure that the VIPBadge_ID is correct, as its possible that you have the wrong ID.

Sorry for the really late response, but I tried this and it works perfectly, thank you!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.