Im trying to make a module that checks how many badges a plr has from my game.
I have tried multiple ways to achieve this but i cannot get it to work.
Eventually when the plr has for example 1 badge and he types something in the chat it will show [I] [grouprank] plr.Name.
Module 1:
function module.AchievableRanks()
local AchievableRoles = {
"I"; -- 1 Badge
"II"; -- 3 Badges
"III"; -- 7 Badges
"IV"; -- 12 Badges
"V"; -- 18 Badges
"VI" -- 25 Badges
}
return AchievableRoles
end
Module 2:
function module.BadgeIDs()
local AchievableRoles = {
2124972910; -- You Joined!
2124972899 -- Met The Creator!
}
return AchievableRoles
end
Module 3: The codes shown above are fine, This is the one im trying to get fixed.
-- // Services
local BadgeService = game:GetService("BadgeService")
local PlayerService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
-- // Modules
local Ranks = require(ReplicatedStorage.Modules["Ranks-Badges"].Ranks)
local chatService = require(ServerScriptService:WaitForChild('ChatServiceRunner'):WaitForChild('ChatService'))
-- // Variables
local groupId = 7628430
local count = 0
-- // Table
local module = {}
-- // Functions
local function doSomethingWithBadge(BadgeName, badgeId)
local s, e = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if s then return e end
return nil
end
function module:CreateChatTags(plr)
local speaker = chatService:GetSpeaker(plr)
if PlayerService[plr]:IsInGroup(groupId) then
local PlayerRank = PlayerService[plr]:GetRoleInGroup(groupId)
--[[for badgeName, badgeId in pairs(Ranks.BadgeIDs()) do
coroutine.resume(coroutine.create(function()
local badge = doSomethingWithBadge(badgeName, badgeId)
if badge ~= nil then
print(badge)
end
end))
end]]
for _, id in ipairs(Ranks.BadgeIDs()) do
local Success, Res = pcall(function()
print(id)
return BadgeService:UserHasBadgeAsync(plr.UserId, id)
end)
end
speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
speaker:SetExtraData('Tags', {{TagText = PlayerRank, TagColor = Ranks.GroupRanks()[PlayerRank]}})
else
speaker:SetExtraData('NameColor', Color3.fromRGB(255, 255, 255))
speaker:SetExtraData('Tags', {{TagText = "Guest", TagColor = Color3.fromRGB(255, 255, 127)}})
end
end
return module