Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is it possible to use more than one badge with UserHasBadgeAsync?

I am currently making a ClickDetector system where if you don't have certain badges you can not enter a room. I want to know if it is possible to add more than one badges to the badgeid variable. Here is my code so far:

local Capsule = script.Parent.Parent
local LeftDoor = Capsule.LeftDoor
local RightDoor = Capsule.RightDoor
local ClickDetector = script.Parent.ClickDetector
local BadgeService  = game:GetService("BadgeService")
local badgeid = 0000000


ClickDetector.MouseClick:Connect(function(plr)
	if BadgeService:UserHasBadgeAsync(plr.UserId, badgeid) then
		--yet to add stuff here
	end
end)

1 answer

✓ Accepted answer

You can simply add more conditions to your conditional statement, or just more conditional statements.

ClickDetector.MouseClick:Connect(function(plr)
	if BadgeService:UserHasBadgeAsync(plr.UserId, badgeid) and BadgeService:UserHasBadgeAsync(plr.UserId, badgeid2) then
		--yet to add stuff here
	end
end)

or

ClickDetector.MouseClick:Connect(function(plr)
	if BadgeService:UserHasBadgeAsync(plr.UserId, badgeid) then
		--player has badge 1, check for badge 2
		if BadgeService:UserHasBadgeAsync(plr.UserId, badgeid2) then
			--yet to add stuff here
		end
	end
end)

Also worth noting that :UserHasBadgeAsync can only be used a limited amount of time in a 1 minute period. It's generally plenty, but if this is a high traffic area of your game with lots of players, you may end up reaching the limit. If you do, sometimes it's worth having a 'BadgeHandler' of sorts, which basically keeps tabs on what badges each player in your game currently owns. All you do is check badge ownership when a player joins your game, and store that information in a table for the duration of the player's session. Did they earn a badge in the current session? Update the BadgeHandler! This way you can check the BadgeHandler's tables for badge ownership any amount of times without constantly querying Roblox. A similar logic is usually applied to datastore systems.

This discussion is preserved as it was. New answers, comments, and votes are closed.