TextChatService Tags for Players with Badge

Im trying to make a tag system, it does work fine with using tables, however I can’t check the badge of an user because it runs on a local script for each player.

How can I solve this problem?

Module Script
local AdminList = {
	OwnerId = 
		691242759,   -- gunsgamertv,
	DevList = {
		2262988748,  -- CrystalSniperOwO
		4723935845,  -- SuperStrong_player
		
		4563988427,  -- farmero123bot
		3169363636,  -- S0moaly
		
	},
	AdminList = {},
	ModList = {
		371423168,	--	nest7331
	},
	TesterList = {
		394800974,	--	Charbel0719
		1623563821,	--	weakles_yt
	},
	IsVIP = function(Player)
		if Player then
			if Player:IsFriendsWith(691242759) then
				return true
			else
				local success, ownsGamePass = pcall(function()
					return MarketplaceService:UserOwnsGamePassAsync(Player.UserId, FrameWork.FrameWork.Gamepasses.VIP)
				end)
				if success and ownsGamePass then
					return true
				else
					return false
				end
			end
		else
			warn("Error when checking IsVIP()")
			return false
		end
	end,
	
	IsPreAlpha = function(Player)
		if BadgeService:UserHasBadgeAsync(Player.UserId, FrameWork.Badges.PreAlphaID) then
			return true
		else
			return false
		end
	end,
	
	IsAlpha = function(Player)
		if BadgeService:UserHasBadgeAsync(Player.UserId, FrameWork.Badges.AlphaID) then
			return true
		else
			return false
		end
	end,
}
Local Script
TextChatService.OnIncomingMessage = function(message)
		if message.TextSource then
			local properties = Instance.new("TextChatMessageProperties")
			local textSourcePlayer = message.TextSource
			local Plr = Players:GetPlayerByUserId(textSourcePlayer.UserId)
			if Plr.UserId==OwnerId then
				properties.PrefixText = "<font color='#ff0000'>[Owner]</font> " .. message.PrefixText
			elseif table.find(DevList, textSourcePlayer.UserId) then
				properties.PrefixText = "<font color='#ff0000'>[Dev]</font> " .. message.PrefixText
			elseif table.find(AdminList, textSourcePlayer.UserId) then
				properties.PrefixText = "<font color='#ff1100'>[Admin]</font> " .. message.PrefixText
			elseif table.find(ModList, textSourcePlayer.UserId) then
				properties.PrefixText = "<font color='#0000ff'>[Mod]</font> " .. message.PrefixText
			elseif table.find(TesterList, textSourcePlayer.UserId) then
				properties.PrefixText = "<font color='#00aaff'>[Tester]</font> " .. message.PrefixText
			elseif IsVIP(Plr) then
				properties.PrefixText = "<font color='#ffaa00'>[VIP]</font> " .. message.PrefixText
			elseif IsPreAlpha(Plr) then
				properties.PrefixText = "<font color='#ffaa00'>[Pre-Alpha]</font> " .. message.PrefixText
			elseif IsAlpha(Plr) then
				properties.PrefixText = "<font color='#ffaa00'>[Alpha]</font> " .. message.PrefixText
			end
			return properties
		end
	end
3 Likes

The error shows you can’t check a player’s badge on the client unless it’s the LocalPlayer. Even then, running those API calls (which should be using pcalls, by the way) each time a message is sent will impact performance.

Instead, I’d recommend using attributes that are set on the server and checked on the client. This way, you can avoid the performance issues and the error.

1 Like

How exactly could I do this?
Like, how would I check the attributes set by the server, from the client?

1 Like

player:GetAttribute()
player:SetAttribute()

1 Like

Okay, I’ll try to rewritte my scripts. Thanks

2 Likes

Also, one thing more, would I have to to set these attributes for the Tables also? Or only for the tags given by badges?

1 Like

Check if the player owns the badge in a server script and edit the attribute to true if they own it

And then check the attribute in a local script

Yeah, you only need the attributes for the badge ones. Don’t forget about the new method for batch checking badges if you need it.

How do I use this batch checking? I never heard of this before.

It’s new.
Check Badge Awards in Batches with CheckUserBadgesAsync - Updates / Announcements - Developer Forum | Roblox

BadgeService:CheckUserBadgesAsync()

1 Like

Thanks for all the replies, I will check in my next test session if the bugs have been fixed!

1 Like