Overhead not showing up when player resets

I’m currently scripting for a group that had an overhead script already in place when I was hired, but it has one problem - the overhead won’t show up when a player resets or dies.

Script:

--# Services

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

--# Modules & Folders

local Remotes = ReplicatedStorage.Resources.RemoteEvents

--# Variables

local Overhead = ReplicatedStorage.GochiOverhead

local FocusSignal = Remotes.FocusSignal

local VIP = 0

--# Functions

local function OptimizeTags(Player)
	repeat wait() until Player.Character or Player.CharacterAdded:Wait()
	
	if Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead") then
		return
	end
	
	local Clone = Overhead:Clone()
	local Badges = Clone.Badges
	Clone.Parent = Player.Character.Head
	Clone.Adornee = Player.Character.Head
	Clone.Name = "GochiOverhead"
	Clone.Username.Text = Player.Name .. " (" .. Player.DisplayName .. ")"
	Clone.Rank.Text = Player:GetRoleInGroup(5874921)
	
	--# Badges
	
	-- Format: [User ID] = "Username"
	
	local HeartID = {
	}
	
	local Donator = {
	}
	
	local Influental = {
	}
	
	local Group = 5874921
	
	if HeartID[Player.UserId] then
		Badges.Heart.Visible = true
	end
	
	if Donator[Player.UserId] then
		Badges.Money.Visible = true
	end
	
	if Influental[Player.UserId] then
		Badges.Check.Visible = true
	end
	
	if Player:GetRankInGroup(Group) >= 252 then
		Badges.Crown.Visible = true
	end
	
	if Player:GetRankInGroup(Group) >= 160 then
		Badges.Hammer.Visible = true
	end
	
	if Player:GetRankInGroup(Group) == 225 or Player:GetRankInGroup(Group) == 252 then
		Badges.Gear.Visible = true
	end
	
	if Player:GetRankInGroup(Group) == 20 then
		Badges.Handshake.Visible = true
	end
	
	
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, VIP) then
		for i = 1,255 do
			Clone.Username.TextColor3 = Color3.fromHSV(i/255, 1, 1)
			wait()
		end
	end
	
end


local function WindowFocus(Player, Status)
	if Status == true then
		local Tags = Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead")
		Tags.Username.Text = "AFK | " .. Player.Name .. " (" .. Player.DisplayName .. ")"
		Player.Character.Humanoid.JumpPower = 0
		Player.Character.Humanoid.WalkSpeed = 0
	elseif Status == false then
		local Tags = Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead")
		Tags.Username.Text =  Player.Name .. " (" .. Player.DisplayName .. ")"
		Player.Character.Humanoid.JumpPower = 7.5
		Player.Character.Humanoid.WalkSpeed = 16
	end
end

--# Implicits

Players.PlayerAdded:Connect(function(Player)
	OptimizeTags(Player)	
	local Character = Player.Character or Player.CharacterAdded:Wait()
	Character:WaitForChild("Humanoid").Died:Connect(function()
		OptimizeTags(Player)
	end)
end)

FocusSignal.OnServerEvent:Connect(function(Player, Status)
	if not Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead") then
		OptimizeTags(Player)
	end
	WindowFocus(Player, Status)
end)

Any ideas as to why the overhead doesn’t show up upon reset?

Can you please provide a video?

Use player.CharacterAdded:Connect() because you are only doing the CharacterAdded:Wait() once and when the character dies, it is deleted from the explorer and re-added. (refreshing the entire character)

--# Services

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

--# Modules & Folders

local Remotes = ReplicatedStorage.Resources.RemoteEvents

--# Variables

local Overhead = ReplicatedStorage.GochiOverhead

local FocusSignal = Remotes.FocusSignal

local VIP = 0

--# Functions

local function OptimizeTags(Player)

	
	if Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead") then
		return
	end
	
	local Clone = Overhead:Clone()
	local Badges = Clone.Badges
	Clone.Parent = Player.Character.Head
	Clone.Adornee = Player.Character.Head
	Clone.Name = "GochiOverhead"
	Clone.Username.Text = Player.Name .. " (" .. Player.DisplayName .. ")"
	Clone.Rank.Text = Player:GetRoleInGroup(5874921)
	
	--# Badges
	
	-- Format: [User ID] = "Username"
	
	local HeartID = {
	}
	
	local Donator = {
	}
	
	local Influental = {
	}
	
	local Group = 5874921
	
	if HeartID[Player.UserId] then
		Badges.Heart.Visible = true
	end
	
	if Donator[Player.UserId] then
		Badges.Money.Visible = true
	end
	
	if Influental[Player.UserId] then
		Badges.Check.Visible = true
	end
	
	if Player:GetRankInGroup(Group) >= 252 then
		Badges.Crown.Visible = true
	end
	
	if Player:GetRankInGroup(Group) >= 160 then
		Badges.Hammer.Visible = true
	end
	
	if Player:GetRankInGroup(Group) == 225 or Player:GetRankInGroup(Group) == 252 then
		Badges.Gear.Visible = true
	end
	
	if Player:GetRankInGroup(Group) == 20 then
		Badges.Handshake.Visible = true
	end
	
	
	if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, VIP) then
		for i = 1,255 do
			Clone.Username.TextColor3 = Color3.fromHSV(i/255, 1, 1)
			wait()
		end
	end
	
end


local function WindowFocus(Player, Status)
	if Status == true then
		local Tags = Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead")
		Tags.Username.Text = "AFK | " .. Player.Name .. " (" .. Player.DisplayName .. ")"
		Player.Character.Humanoid.JumpPower = 0
		Player.Character.Humanoid.WalkSpeed = 0
	elseif Status == false then
		local Tags = Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead")
		Tags.Username.Text =  Player.Name .. " (" .. Player.DisplayName .. ")"
		Player.Character.Humanoid.JumpPower = 7.5
		Player.Character.Humanoid.WalkSpeed = 16
	end
end

--# Implicits

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(char)
		OptimizeTags(Player)
	end)
end)

FocusSignal.OnServerEvent:Connect(function(Player, Status)
	if not Player.Character:WaitForChild("Head"):FindFirstChild("GochiOverhead") then
		OptimizeTags(Player)
	end
	WindowFocus(Player, Status)
end)
4 Likes

https://gyazo.com/fd28f490a001b25f906635931a84cd64