Script keeps putting random usernames above players

Usernames are going on random players. My username was my developers username, and most of the time, my username was on other players.

local groupID = 32989980
local ESFOZA = 33923463
local HQ = 33923356
local RG = 33534442
local TERDAC = 33923286
local ZAAF = 33923232
local ZAMPC = 33923505

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local function SetupOverheadUI(player, character)
	local head = character:WaitForChild("HumanoidRootPart")
	local overheadUI = script.OverheadGUI:Clone()
	
	overheadUI.Parent = head

	overheadUI.PlrName.Text = player.Name
	overheadUI.PlrRank.Text = player:GetRoleInGroup(groupID)

	local division = overheadUI.Divisions

	if player:GetRankInGroup(groupID) == 255 then
		division.DivName.Text = "[Z] Director"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 254 then
		division.DivName.Text = "[HDEV] Head Developer"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 253 then
		division.DivName.Text = "[DEV] Developer"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 252 then
		division.DivName.Text = "[CZA] Chairman of ZA"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 251 then
		division.DivName.Text = "[AA] Arch Admiral"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 250 then
		division.DivName.Text = "[A] Admiral"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 249 then
		division.DivName.Text = "[CO] Commander"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 22 then
		division.DivName.Text = "[Z10] General"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 21 then
		division.DivName.Text = "[Z9] Lieutenant General"
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 20 then
		division.DivName.Text = "[Z8] Major General"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 19 then
		division.DivName.Text = "[Z7] Brigadier General"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 18 then
		division.DivName.Text = "[Z6] Colonel"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 17 then
		division.DivName.Text = "[Z5] Lieutenant Colonel"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 16 then
		division.DivName.Text = "[Z4] Major"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 15 then
		division.DivName.Text = "[Z3] Captain"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 14 then
		division.DivName.Text = "[Z2] First Lieutenant"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 13 then
		division.DivName.Text = "[Z1] Second Lieutenant"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 43)
	elseif player:GetRankInGroup(groupID) == 11 then
		division.DivName.Text = "[R11] Command Sergeant Major"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(24, 255, 217)
	elseif player:GetRankInGroup(groupID) == 10 then
		division.DivName.Text = "[R10] Sergeant Major"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(49, 255, 248)
	elseif player:GetRankInGroup(groupID) == 9 then
		division.DivName.Text = "[R9] First Sergeant"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(49, 255, 248)
	elseif player:GetRankInGroup(groupID) == 8 then
		division.DivName.Text = "[R8] Master Sergeant"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(49, 255, 248)
	elseif player:GetRankInGroup(groupID) == 7 then
		division.DivName.Text = "[R7] Sergeant First Class"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(49, 255, 248)
	elseif player:GetRankInGroup(groupID) == 6 then
		division.DivName.Text = "[R6] Staff Sergeant"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(49, 255, 248)
	elseif player:GetRankInGroup(groupID) == 5 then
		division.DivName.Text = "[R5] Sergeant"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(49, 255, 248)
	elseif player:GetRankInGroup(groupID) == 4 then
		division.DivName.Text = "[R4] Corporal"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(125, 125, 125)
	elseif player:GetRankInGroup(groupID) == 3 then
		division.DivName.Text = "[R3] Specialist"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(125, 125, 125)
	elseif player:GetRankInGroup(groupID) == 2 then
		division.DivName.Text = "[R2] Private First Class"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(125, 125, 125)
	elseif player:GetRankInGroup(groupID) == 1 then
		division.DivName.Text = "[R1] Private [Combat Training]"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(125, 125, 125)
	elseif player:IsInGroup(ESFOZA) then
		division.DivName.Text = "[ESFOZA] "..player:GetRoleInGroup(ESFOZA)
		division.DivImage.Image = "rbxassetid://16514196686"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(190, 180, 172)
	elseif player:IsInGroup(TERDAC) then
		division.DivName.Text = "[TERDAC] "..player:GetRoleInGroup(TERDAC)
		division.DivImage.Image = "rbxassetid://16513878352"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 48, 6)
	elseif player:IsInGroup(RG) then
		division.DivName.Text = "[RG] "..player:GetRoleInGroup(RG)
		division.DivImage.Image = "rbxassetid://16433575026"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 162, 0)
	elseif player:IsInGroup(ZAMPC) then
		division.DivName.Text = "[ZAMPC] "..player:GetRoleInGroup(ZAMPC)
		division.DivImage.Image = "rbxassetid://16514272731"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 98, 25)
	elseif player:IsInGroup(ZAAF) then
		division.DivName.Text = "[ZAAF] "..player:GetRoleInGroup(ZAAF)
		division.DivImage.Image = "rbxassetid://16513766481"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(58, 252, 255)
	elseif player:IsInGroup(HQ) then
		division.DivName.Text = "[HQ] "..player:GetRoleInGroup(HQ)
		division.DivImage.Image = "rbxassetid://16514021179"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(255, 167, 26)
	elseif player:IsInGroup(groupID) then
		division.DivName.Text = "Divisionless"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(152, 166, 177)
	else
		division.DivName.Text = "Civilian"
		division.DivImage.Image = "rbxassetid://17365601663"
		division.DivDesign.BackgroundColor3 = Color3.fromRGB(170, 0, 255)
	end


	if UIS.TouchEnabled and not UIS.KeyboardEnabled then
		overheadUI.Icons.Mobile.Visible = true
	elseif UIS.KeyboardEnabled and not UIS.TouchEnabled then
		overheadUI.Icons.PC.Visible = true
	end

end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		SetupOverheadUI(player, Character)
	end)
end)
2 Likes

PLEASE


Tell me this is a troll :sob:

2 Likes

First of all, here is a tip to optimise this monster of a code:

local ranks = {
[255] = {"[Z] Director", "rbxassetid://16514021179", Color3.fromRGB(255, 167, 43)}
-- and so on!
}
local rank = player:GetRankInGroup(groupID)
division.DivName.Text = ranks[rank][1]	division.DivImage.Image = ranks[rank][2] 		division.DivDesign.BackgroundColor3 = ranks[rank][3]

Just add more ranks in the same format in the ranks table to make the code better
For other groups you can use the same table but replace the rank number with the group id and loop through it to see of player is in said group.

And I don’t get the issue? Please show images.

1 Like

this is not my username, I was with my developer in the game and his username went to mine.

I know it looks bad. Haha.

I come to you all to help me out and fix issues.

1 Like

The only issue I see is that the code is extremely ugly. Though, maybe the existance of the function could be the issue? The logic seems fine.

Print the name of the player and see if it’s their actual name or yours.

I feel you could have another variable with the same variable name [player] (in the global scope) that has a value with your username

Just for confirmation, the Role is correct?

Are you able to send me the correct code?

Yes. The role is correct. But that is not my username. It will keep going above players duplicating the same username.

You able to send me the correct script code?

Well, uh, no. We are here to help you understand, not give an entire script to you.

Noted. Do you know the main problem? Of why the nametag keeps changing on top of players (changes from my username to the one listed above, which is my devs username.)

The roles work, just the username is the issue.

local groupID = 32989980
local ESFOZA = 33923463
local HQ = 33923356
local RG = 33534442
local TERDAC = 33923286
local ZAAF = 33923232
local ZAMPC = 33923505

local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")

local ranks = {
    [255] = {Name = "[Z] Director", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [254] = {Name = "[HDEV] Head Developer", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [253] = {Name = "[DEV] Developer", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [252] = {Name = "[CZA] Chairman of ZA", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [251] = {Name = "[AA] Arch Admiral", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [250] = {Name = "[A] Admiral", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [249] = {Name = "[CO] Commander", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [22] = {Name = "[Z10] General", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [21] = {Name = "[Z9] Lieutenant General", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 43)},
    [20] = {Name = "[Z8] Major General", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [19] = {Name = "[Z7] Brigadier General", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [18] = {Name = "[Z6] Colonel", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [17] = {Name = "[Z5] Lieutenant Colonel", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [16] = {Name = "[Z4] Major", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [15] = {Name = "[Z3] Captain", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [14] = {Name = "[Z2] First Lieutenant", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [13] = {Name = "[Z1] Second Lieutenant", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(255, 167, 43)},
    [11] = {Name = "[R11] Command Sergeant Major", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(24, 255, 217)},
    [10] = {Name = "[R10] Sergeant Major", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(49, 255, 248)},
    [9] = {Name = "[R9] First Sergeant", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(49, 255, 248)},
    [8] = {Name = "[R8] Master Sergeant", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(49, 255, 248)},
    [7] = {Name = "[R7] Sergeant First Class", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(49, 255, 248)},
    [6] = {Name = "[R6] Staff Sergeant", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(49, 255, 248)},
    [5] = {Name = "[R5] Sergeant", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(49, 255, 248)},
    [4] = {Name = "[R4] Corporal", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(125, 125, 125)},
    [3] = {Name = "[R3] Specialist", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(125, 125, 125)},
    [2] = {Name = "[R2] Private First Class", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(125, 125, 125)},
    [1] = {Name = "[R1] Private [Combat Training]", Image = "rbxassetid://17365601663", Color = Color3.fromRGB(125, 125, 125)}
}

local divisions = {
    [ESFOZA] = {Prefix = "[ESFOZA]", Image = "rbxassetid://16514196686", Color = Color3.fromRGB(190, 180, 172)},
    [TERDAC] = {Prefix = "[TERDAC]", Image = "rbxassetid://16513878352", Color = Color3.fromRGB(255, 48, 6)},
    [RG] = {Prefix = "[RG]", Image = "rbxassetid://16433575026", Color = Color3.fromRGB(255, 162, 0)},
    [ZAMPC] = {Prefix = "[ZAMPC]", Image = "rbxassetid://16514272731", Color = Color3.fromRGB(255, 98, 25)},
    [ZAAF] = {Prefix = "[ZAAF]", Image = "rbxassetid://16513766481", Color = Color3.fromRGB(58, 252, 255)},
    [HQ] = {Prefix = "[HQ]", Image = "rbxassetid://16514021179", Color = Color3.fromRGB(255, 167, 26)}
}

local function SetupOverheadUI(player, character)
    local head = character:WaitForChild("HumanoidRootPart")
    local overheadUI = script.OverheadGUI:Clone()
    
    overheadUI.Parent = head
    overheadUI.PlrName.Text = player.Name
    overheadUI.PlrRank.Text = player:GetRoleInGroup(groupID)

    local rank = ranks[player:GetRankInGroup(groupID)]
    local division = overheadUI.Divisions

    if rank then
        division.DivName.Text = rank.Name
        division.DivImage.Image = rank.Image
        division.DivDesign.BackgroundColor3 = rank.Color
    else
        local inGroup = false
        for group, info in pairs(divisions) do
            if player:IsInGroup(group) then
                division.DivName.Text = info.Prefix .. " " .. player:GetRoleInGroup(group)
                division.DivImage.Image = info.Image
                division.DivDesign.BackgroundColor3 = info.Color
                inGroup = true
                break
            end
        end
        if not inGroup then
            if player:IsInGroup(groupID) then
                division.DivName.Text = "Divisionless"
                division.DivImage.Image = "rbxassetid://17365601663"
                division.DivDesign.BackgroundColor3 = Color3.fromRGB(152, 166, 177)
            else
                division.DivName.Text = "Civilian"
                division.DivImage.Image = "rbxassetid://17365601663"
                division.DivDesign.BackgroundColor3 = Color3.fromRGB(170, 0, 255)
            end
        end
    end

    if UIS.TouchEnabled and not UIS.KeyboardEnabled then
        overheadUI.Icons.Mobile.Visible = true
    elseif UIS.KeyboardEnabled and not UIS.TouchEnabled then
        overheadUI.Icons.PC.Visible = true
    end
end

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        SetupOverheadUI(player, character)
    end)
end)

Give this a try, I didn’t test it however, so let me know if this doesn’t work.

I’ve also gone ahead and did what K4ttt_i told you do to earlier for you.

2 Likes

Thank you a lot. Appreciate your help and it worked perfectly. I will let you know if any problems consist.

Awesome, glad to hear!!

LMK!

(30 space characters)

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