Ranking System Math Problem

Hi I’m working on a modular overhead rank system with tags.
Tag Screenshot:
image
Tag Defaults:
image
By tags I mean rectangles above your head with text, for example Premium, Staff, Developer.
If they own a gamepass, they get the tag for it.

I’ve worked out a way to do it but I’m having trouble making it work math-wise.
The tags are going to be dynamic, depending on the textbounds the tag will resize itself accordingly before being inserted to the player’s overhead.

I’m trying to work out a way I can do this mathmatically as I’m not the best at math lol.
I need the tags to have padding of 0.02 and for all the tags together to be centered.
My tags are currently anchorpointed??? at 0.5,0.5.

My current script snippet is here:

local Ranks = {
	
	Premium = {
		-- Config
		OverheadText = "Premium",
		OverheadFont = "GothamBold",
		OverheadColor = Color3.fromRGB(0, 85, 127),
		-- Permissions (who will have it)
		UserIds = {000},
		BadgeIds = {000},
		GroupRanks = {000},
		Gamepasses = {14751366},
	},
	Premium2 = {
		-- Config
		OverheadText = "Premium222",
		OverheadFont = "GothamBold",
		OverheadColor = Color3.fromRGB(170, 0, 255),
		-- Permissions (who will have it)
		UserIds = {304343782},
		BadgeIds = {000},
		GroupRanks = {000},
		Gamepasses = {2},
	},
	
}

	
function Boot(Player)
	Player.Character.Head.Rank.Template.Visible = false
	for _, Tab in pairs(Ranks) do
		for _, UserId in pairs(Tab.UserIds) do
			if UserId == Player.UserId then
				AddTabToPlayer(Player,Tab)
			end
		end
		for _, BadgeId in pairs(Tab.BadgeIds) do
			if BadgeId > 1000 then
				if game:GetService("BadgeService"):UserHasBadgeAsync(Player.UserId,BadgeId) then
					AddTabToPlayer(Player,Tab)
				end
			end
		end
		for _, Rank in pairs(Tab.GroupRanks) do
			if Player:GetRankInGroup(GroupId) > Rank then
				AddTabToPlayer(Player,Tab)
			end
		end
		for _, Gamepass in pairs(Tab.Gamepasses) do
			if Gamepass > 1000 then
				if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player.UserId,Gamepass) == true then
					AddTabToPlayer(Player,Tab)
				end
			end
		end
	end
end

function AddTabToPlayer(Player,Tab)
	if Player.MocaexValues:FindFirstChild("TabsEnabled") and not Player.Character.Head.Rank:FindFirstChild(Tab.OverheadText) then
		local TabsEnabled = Player.MocaexValues.TabsEnabled.Value
		TabsEnabled = TabsEnabled + 1
		
		local NewTab = Player.Character.Head.Rank.Template:Clone()
		NewTab.Parent = Player.Character.Head.Rank
		NewTab.Visible = true
		NewTab.Name = Tab.OverheadText
		NewTab.Text.Text = Tab.OverheadText
		NewTab.Text.Font = Tab.OverheadFont
		NewTab.ImageColor3 = Tab.OverheadColor
		local fullsize = 0
		for _, Tab in ipairs(Player.Character.Head.Rank:GetChildren()) do
			if Tab.Name ~= "Template" and Tab.ClassName == "ImageLabel" then
				fullsize = fullsize + Tab.Size.X.Scale
			end
		end
		local PositionToMinus = fullsize / TabsEnabled
		for _, Tab in ipairs(Player.Character.Head.Rank:GetChildren()) do
			if Tab.Name ~= "Template" and Tab.ClassName == "ImageLabel" then
				print(Tab.Name)
				
				Tab.Position = UDim2.new(Tab.Position.X.Scale - PositionToMinus,Tab.Position.X.Offset,Tab.Position.Y.Scale,Tab.Position.Y.Offset)	
			end
		end
	end
end

Couldn’t you just use a UIListLayout to automatically add padding? I do that for these badges:

1 Like

That’s my last resort. I want to animate the position, so if a player purchases premium in-game, an event is fired and the Premium tag animates over their head

i like polishing my game alot

This is still possible, with a UIListLayout you can have a “template” frame and tween the vertical size of it, then you can tween the tag in from that. That’s how I made this.

oh wow you made that cool sword game

Anyways thanks for the help ill try it out

1 Like