plr:GetRoleInGroup() doesn't work properly

I want my rank tag gui to show what division they’re in and then the rank for that division.
Here is the script:

local rep = game.ReplicatedStorage
local rankgui = rep.RankGui
local mainGroup = 35020333
local rem = game.ReplicatedStorage.RemoteEvents


local groups = {
	35028112, -- MP = 1
	35021045, -- 101AB = 2
	35025168, -- 2AD = 3
	35041176, -- QM = 4
}

rem.LoadRankTag.OnServerEvent:Connect(function(plr)
	local tag = rankgui:Clone()
	local frame = tag.Frame
	tag.Parent = plr.Character:FindFirstChild("Head")

	tag.Frame.DisplayName.Text = plr.Name
	tag.Frame.DisplayName.TextColor = plr.TeamColor
	tag.Frame.Rank.Text = plr:GetRoleInGroup(mainGroup)
	
	if plr:GetRankInGroup(mainGroup) >= 254 then
		tag.Frame.Division.Text = "General Headquarters"
	end
	
	if plr:IsInGroup(groups[1]) then
		tag.Frame.Division.Text = "Military Police - " .. plr:GetRoleInGroup(groups[1])
	end
	
	if plr:IsInGroup(groups[2]) then
		tag.Frame.Division.Text = "101st Airborne Division - " .. plr:GetRoleInGroup(groups[2])
	end
	
	if plr:IsInGroup(groups[3]) then
		tag.Frame.Division.Text = "2nd Armored Division - " .. plr:GetRoleInGroup(groups[3])
	end
	
	
	
	
	
	
		if plr:GetRankInGroup(mainGroup) == 255 then
		frame.RankImage.GOA.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 254 then
		frame.RankImage.GEN.Visible = true	
		elseif plr:GetRankInGroup(mainGroup) == 18 then
		frame.RankImage.GEN.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 17 then
		frame.RankImage.LTGEN.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 16 then
		frame.RankImage.MGEN.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 15 then
		frame.RankImage.BGEN.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 14 then
		frame.RankImage.COL.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 13 then
		frame.RankImage.LTCOL.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 12 then
		frame.RankImage.MAJ.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 11 then
		frame.RankImage.CPT.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 10 then
		frame.RankImage.FLT.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 9 then
		frame.RankImage.SLT.Visible = true

		elseif plr:GetRankInGroup(mainGroup) == 8 then
		frame.RankImage.MSGT.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 7 then
		frame.RankImage.FSGT.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 6 then
		frame.RankImage.TSGT.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 5 then
		frame.RankImage.SSGT.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 4 then
		frame.RankImage.SGT.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 3 then
		frame.RankImage.CPL.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 2 then
		frame.RankImage.PFC.Visible = true
		elseif plr:GetRankInGroup(mainGroup) == 1 then
	end
end)

It works fine except for the fact it doesn’t show the correct rank in the group. I’ve double checked and I am under the rank Awaiting Placement in the group and the group ID is correct yet my ranktag says “Military Police - Guest”. I don’t know why, any help would be appreciated.

Screenshot 2024-10-17 181545

Are you sure you are in the group? Guest means you aren’t a part of that group.

EDIT: mb you are

I searched it up and apparently server side scripts don’t get the most up-to-date information in the group.

You could fire a remote event to all clients where it shows the label instead.

How would I do that?

eeeeeeeeeeeeeee

Make a local script and a new event.

Now inside the local script make a .onclientevent(player (the one that has the tag))

now just copy and paste the code from the onserverevent to the onclientevent

1 Like

I personally use Player:GetRankInGroup(), then match the returned integer with a string (the rank name) in a ModuleScript.

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