Badge overhead text only showing when player respawns

I have a overhead gui that works fine, but I’ve made it so if a player owns a badge it will show a text saying “early tester” but it only shows if the player dies (sometimes but rarely it will show without dying)

Let me also add that it’s in a place connected to a game (the game is the main menu and you select maps which is the places)

image

Here is the OverheadGui Script V

local Players = game:GetService("Players")

local rankInformation = require(script.RankInformation)

local connections = {}
local overHeadTemplate = script.OverheadGui

Players.PlayerAdded:Connect(function (player)
	connections[player] = player.CharacterAdded:Connect(function (character)
		local newOverhead = overHeadTemplate:Clone()
		
		newOverhead.PlayerName.Text = player.Name
		
		for _, info in pairs (rankInformation) do
			local isPlayerInDivision = player:IsInGroup(info.groupId)
			
			if isPlayerInDivision then
				newOverhead.Group.Text = info.name
				newOverhead.Group.TextColor3 = info.color
				newOverhead.Group.Visible = true
				
				newOverhead.Rank.Text = player:GetRoleInGroup(info.groupId)
				newOverhead.Rank.Visible = true
			end
		end
		
		character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		newOverhead.Parent = character:WaitForChild("HumanoidRootPart")
	end)
end)


local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local badgeID = 2124845563  -- Change this to your badge ID

local connections = {}
local overHeadTemplate = script.OverheadGui

local function onPlayerAdded(player)
	-- Check if the player has the badge
	local success, hasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
	end)

	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player has badge!")
		return
	end

	if hasBadge then

		overHeadTemplate.Tester.Visible = true -- this shows the text
	end
end

-- Connect "PlayerAdded" events to the "onPlayerAdded()" function
Players.PlayerAdded:Connect(onPlayerAdded)


Players.PlayerRemoving:Connect(function (player)
	if connections[player] then
		connections[player]:Disconnect()
		connections[player] = nil
	end
end)

Here is the RankInformation Module script

return {
	{
		name = "Zentryte",
		color = Color3.fromRGB(0, 170, 255),
		groupId = 3371398
	},
	{
		name = "name",
		color = Color3.fromRGB(255, 0, 0),
		groupId = 0
	}
}

Please let me not I did not make this script cause I’m basic at scripting lol not the greatest but learning.

I used this video for the over head gui-> Rank Overhead GUI - ROBLOX - YouTube

then I used this to help me with showing the text - > BadgeService:UserHasBadgeAsync

just strange why it wont always show when the player joins only when they die it shows?

Maybe there is a way to instantly kill the player and instantly spawn them back when they join and it wont kill them again? only when they join idk

thx!

You didn’t mention errors produced (or not) in output by your code. It can help a lot.

There are no errors, It only shows after resetting.

1 Like

This piece of code is questionable:

local function onPlayerAdded(player)
	-- Check if the player has the badge
	local success, hasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, badgeID) or true
	end)

	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player has badge!")
		return
	end

	if hasBadge then

		overHeadTemplate.Tester.Visible = true --// mistake
	end
end

In this function everything is fine, expect one thing - the script makes the Tester label stored in that script visible if any player with the badge joins your game. Why this task is not performed on a new, cloned overhead GUI, like earlier in the script? I mean this piece of code:

Players.PlayerAdded:Connect(function (player)
	connections[player] = player.CharacterAdded:Connect(function (character)
		local newOverhead = overHeadTemplate:Clone() --// I mean this

		newOverhead.PlayerName.Text = player.Name

		for _, info in pairs (rankInformation) do
			local isPlayerInDivision = player:IsInGroup(info.groupId) or true

			if isPlayerInDivision then
				newOverhead.Group.Text = info.name
				newOverhead.Group.TextColor3 = info.color
				newOverhead.Group.Visible = true

				newOverhead.Rank.Text = player:GetRoleInGroup(info.groupId)
				newOverhead.Rank.Visible = true
			end
		end

		character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		newOverhead.Parent = character:WaitForChild("HumanoidRootPart")
	end)
end)

Shouldn’t you be parenting the overhead text to the character’s Head and not the HumanoidRootPart?

1 Like

No. You can check it in Roblox Studio. Overhead Gui - Roblox. This is a game version of Rank Overhead GUI - ROBLOX - YouTube and @Zentryte was following this tutorial. In this work this can be seen (piece of code):

Players.PlayerAdded:Connect(function (player)
	connections[player] = player.CharacterAdded:Connect(function (character)
		local newOverhead = overHeadTemplate:Clone()
		
		newOverhead.PlayerName.Text = player.Name
		
		for _, info in pairs (rankInformation) do
			local isPlayerInDivision = player:IsInGroup(info.groupId)
			
			if isPlayerInDivision then
				newOverhead.Group.Text = info.name
				newOverhead.Group.TextColor3 = info.color
				newOverhead.Group.Visible = true
				
				newOverhead.Rank.Text = player:GetRoleInGroup(info.groupId)
				newOverhead.Rank.Visible = true
			end
		end
		
		character:WaitForChild("Humanoid").DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		newOverhead.Parent = character:WaitForChild("HumanoidRootPart") -- parenting to root part
	end)
end)

I also prefer parenting to player’s head, but this also works.

1 Like