Overhead Script

Hi! i’ve made this overhead script with all group ranks, and it works, but idk why it will only insert it on my charachter and not on the other else, there isn’t any correlation with my user, so strange

--Variables
local players = game:GetService("Players")
local SS = game:GetService("ServerStorage")
local nametag = SS:WaitForChild("NameTag")
local idGroup = 15428405



--Table for special names
local Roles = {
	
	["255"] = {title = "Holder", color = Color3.fromRGB(2, 0, 39), mod = true, admin = true, owner = true},
	["254"] = {title = "Creatore", color = Color3.fromRGB(2, 0, 39), mod = true, admin = true, owner = true},
	
	["240"] = {title = "CapoAdmin", color = Color3.fromRGB(41, 8, 138), mod = true, admin = true, owner = false},
	["230"] = {title = "ViceCapoAdmin", color = Color3.fromRGB(7, 57, 111), mod = true, admin = true, owner = false},
	["220"] = {title = "Admin", color = Color3.fromRGB(27, 134, 206), mod = true, admin = true, owner = false},
	
	
	["215"] = {title = "Capo Moderatore", color = Color3.fromRGB(98, 0, 0), mod = true, admin = false, owner = false},
	["212"] = {title = "ViceCapo Moderatore", color = Color3.fromRGB(98, 0, 0), mod = true, admin = false, owner = false},
	["200"] = {title = "Senior Moderatore", color = Color3.fromRGB(117, 0, 0), mod = true, admin = false, owner = false},
	["114"] = {title = "Moderatore", color = Color3.fromRGB(138, 3, 3), mod = true, admin = false, owner = false},
	["110"] = {title = "Junior Moderatore", color = Color3.fromRGB(171, 48, 32), mod = true, admin = false, owner = false},
	["100"] = {title = "Trial Moderatore", color = Color3.fromRGB(171, 73, 43), mod = true, admin = false, owner = false},
	
	
	["1"] = {title = "Membro", color = Color3.fromRGB(159, 135, 58), mod = false, admin = false, owner = false},
	["0"] = {title = "Guest", color = Color3.fromRGB(131, 113, 48), mod = false, admin = false, owner = false}
	
	
}

--Functions

local function addOverhead(player)
	local char = player.Character
	if char then
		local head = char:WaitForChild("Head")
		local newtext = nametag:Clone() --Cloning the text.
		local mainFrame = newtext.Frame.Frame
		local visualName = mainFrame.DisplayName
		local visualNameShadow = mainFrame.DisplayNameShadow
		local nametext = mainFrame.PlayerName
		local nametextShadow = mainFrame.PlayerNameShadow
		local ranktext = mainFrame.Rank
		local Icons = mainFrame.Icons
		local AdminIcon = Icons.Admin
		local OwnerIcon  = Icons.Owner
		local PremiumIcon = Icons.Premium
		local ModIcon = Icons.Mod

		local humanoid = char.Humanoid
		local userId = player.UserId
		local rankGroup = player:GetRankInGroup(idGroup)


		humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None

		--Main Text
		newtext.Parent = head
		newtext.Adornee = head
		nametext.Text = player.Name --Changes the text to the player's name.
		nametextShadow.Text = player.Name

		visualName.Text = player.DisplayName
		visualNameShadow.Text = player.DisplayName


		--"If" Statements
		
		
		--Check if player name is in the specialNames table
		if player.MembershipType == Enum.MembershipType.Premium then
			PremiumIcon.Visible = true
		end
		ranktext.Text = Roles[tostring(rankGroup)].title
		ranktext.TextColor3 = Roles[tostring(rankGroup)].color
		AdminIcon.Visible = Roles[tostring(rankGroup)].admin
		ModIcon.Visible = Roles[tostring(rankGroup)].mod
		OwnerIcon.Visible = Roles[tostring(rankGroup)].owner
	end
end

for _, player in pairs(players:GetPlayers()) do
	addOverhead(player)
end
players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		addOverhead(player)
	end)
end)


Any Help?

2 Likes

Look at this fragment of your code:

for _, player in pairs(players:GetPlayers()) do
	addOverhead(player)
end

Look also at this piece of code:

players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		addOverhead(player)
	end)
end)

I suggest using CharacterAdded event in the first fragment of the code just like it is done in the second given part of your work. Maybe the loop runs the declared function while players characters are nil - we might need to wait for the characters to spawn.

1 Like

i’ve deleted the first fragment that u mentioned, cause it’s a server script and a there’ll always be the server before the players, but the error is still there, i’ve tried to print some things for checking and it works all perfectly fine but somehow it won’t dupe the hoverhead and insert on the char head for other ppl exept of me

1 Like

Where is this server script located?

server script service and the overhead on server storage

Make a new script. Put this script in StarterCharacterScripts and do changes to the script so it will run properly (take an advantage of the fact that character=script.Parent and the script will run every time when a character is added). I hope that this is clear to you but if not - let me know.

this will only be local, so only the intrested player can see it, as i said i’ve tried printing something and the actual character is right, idk what is the error

I recommend connecting addOverhead to CharacterAdded instead because the parameters of it is the character of the player when spawning.

local function addOverhead(char)
	local head = char:WaitForChild("Head")
	...
	OwnerIcon.Visible = Roles[tostring(rankGroup)].owner
end

for _, player in pairs(players:GetPlayers()) do
	player.CharacterAdded:Connect(addOverhead)
end
players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(addOverhead)
end)

And it’s likely that CharacterAdded won’t fire when a player joins (most likely because the character already loaded before trying to fire the event), so you should get its character first, and if the character hasn’t been created yet (character hasn’t loaded yet) wait for it to load using CharacterAdded:Wait() (this also returns the character once the character has loaded

local character = player.Character or player.CharacterAdded:Wait()

then you can connect player.CharacterAdded

for _, player in pairs(players:GetPlayers()) do
	task.spawn(function() -- using task.spawn() so that every player that didn't fire PlayerAdded will fire addOverhead with little to no delay
		local character = player.Character or player.CharacterAdded:Wait()
		addOverhead(character)
		
		player.CharacterAdded:Connect(addOverhead)
	end)
end
players.PlayerAdded:Connect(function(player)
	local character = player.Character or player.CharacterAdded:Wait()
	addOverhead(character)
	
	player.CharacterAdded:Connect(addOverhead)
end)

The final script should look like this

--Variables
local players = game:GetService("Players")
local SS = game:GetService("ServerStorage")
local nametag = SS:WaitForChild("NameTag")
local idGroup = 15428405



--Table for special names
local Roles = {
	
	["255"] = {title = "Holder", color = Color3.fromRGB(2, 0, 39), mod = true, admin = true, owner = true},
	["254"] = {title = "Creatore", color = Color3.fromRGB(2, 0, 39), mod = true, admin = true, owner = true},
	
	["240"] = {title = "CapoAdmin", color = Color3.fromRGB(41, 8, 138), mod = true, admin = true, owner = false},
	["230"] = {title = "ViceCapoAdmin", color = Color3.fromRGB(7, 57, 111), mod = true, admin = true, owner = false},
	["220"] = {title = "Admin", color = Color3.fromRGB(27, 134, 206), mod = true, admin = true, owner = false},
	
	
	["215"] = {title = "Capo Moderatore", color = Color3.fromRGB(98, 0, 0), mod = true, admin = false, owner = false},
	["212"] = {title = "ViceCapo Moderatore", color = Color3.fromRGB(98, 0, 0), mod = true, admin = false, owner = false},
	["200"] = {title = "Senior Moderatore", color = Color3.fromRGB(117, 0, 0), mod = true, admin = false, owner = false},
	["114"] = {title = "Moderatore", color = Color3.fromRGB(138, 3, 3), mod = true, admin = false, owner = false},
	["110"] = {title = "Junior Moderatore", color = Color3.fromRGB(171, 48, 32), mod = true, admin = false, owner = false},
	["100"] = {title = "Trial Moderatore", color = Color3.fromRGB(171, 73, 43), mod = true, admin = false, owner = false},
	
	
	["1"] = {title = "Membro", color = Color3.fromRGB(159, 135, 58), mod = false, admin = false, owner = false},
	["0"] = {title = "Guest", color = Color3.fromRGB(131, 113, 48), mod = false, admin = false, owner = false}
	
	
}

--Functions

local function addOverhead(char)
	local player = players:GetPlayerFromCharacter(char)
	
	local head = char:WaitForChild("Head")
	local newtext = nametag:Clone() --Cloning the text.
	local mainFrame = newtext.Frame.Frame
	local visualName = mainFrame.DisplayName
	local visualNameShadow = mainFrame.DisplayNameShadow
	local nametext = mainFrame.PlayerName
	local nametextShadow = mainFrame.PlayerNameShadow
	local ranktext = mainFrame.Rank
	local Icons = mainFrame.Icons
	local AdminIcon = Icons.Admin
	local OwnerIcon  = Icons.Owner
	local PremiumIcon = Icons.Premium
	local ModIcon = Icons.Mod
	
	local humanoid = char:FindFirstChildOfClass("Humanoid")
	local userId = player.UserId
	local rankGroup = player:GetRankInGroup(idGroup)
	
	
	humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	
	--Main Text
	newtext.Parent = head
	newtext.Adornee = head
	nametext.Text = player.Name --Changes the text to the player's name.
	nametextShadow.Text = player.Name
	
	visualName.Text = player.DisplayName
	visualNameShadow.Text = player.DisplayName
	
	
	--"If" Statements
	
	
	--Check if player name is in the specialNames table
	if player.MembershipType == Enum.MembershipType.Premium then
		PremiumIcon.Visible = true
	end
	ranktext.Text = Roles[tostring(rankGroup)].title
	ranktext.TextColor3 = Roles[tostring(rankGroup)].color
	AdminIcon.Visible = Roles[tostring(rankGroup)].admin
	ModIcon.Visible = Roles[tostring(rankGroup)].mod
	OwnerIcon.Visible = Roles[tostring(rankGroup)].owner
end

local function onPlayerAdded(player: Player)
	local character = player.Character or player.CharacterAdded:Wait()
	addOverhead(character)
	
	player.CharacterAdded:Connect(addOverhead)
end

for _, player in ipairs(players:GetPlayers()) do
	task.spawn(onPlayerAdded, player)
end

players.PlayerAdded:Connect(onPlayerAdded)
2 Likes

so the script is a local script?

nope it’s a server script, i’ve copied and pasted yours but it won’t works anyways …

Screenshot 2023-12-02 144741

look here, i’m the only one who has the overhead, the guy next to me doesn’t, and dw it’s not a local thing, i’ve alr tried.

Are you sure that a server script parented to StartedCharacterScripts will run like a local script? Did I understand you correctly?


If yes, does it mean that the server scripts mentioned in the Roblox API have no rights to run on server side?

the server script is on server script service not starter character

1 Like

Yes, this is correct, you are right. I suggested earlier rebuilding the script and changing its parent so it will run in StarterCharacterScripts instead.

1 Like

Hmm. Try this.

Like what @Spiderr12PL said, make a normal script in StarterCharacterScripts instead so that the script runs everytime the player spaws/respawns.

The script is similar to the original. The difference is that you won’t use Players.PlayerAdded and player.CharacterAdded anymore and you can get the character using script.Parent.

The final script:

--Variables
local players = game:GetService("Players")
local SS = game:GetService("ServerStorage")
local nametag = SS:FindFirstChild("NameTag")
local idGroup = 15428405

local char = script.Parent



--Table for special names
local Roles = {
	
	["255"] = {title = "Holder", color = Color3.fromRGB(2, 0, 39), mod = true, admin = true, owner = true},
	["254"] = {title = "Creatore", color = Color3.fromRGB(2, 0, 39), mod = true, admin = true, owner = true},
	
	["240"] = {title = "CapoAdmin", color = Color3.fromRGB(41, 8, 138), mod = true, admin = true, owner = false},
	["230"] = {title = "ViceCapoAdmin", color = Color3.fromRGB(7, 57, 111), mod = true, admin = true, owner = false},
	["220"] = {title = "Admin", color = Color3.fromRGB(27, 134, 206), mod = true, admin = true, owner = false},
	
	
	["215"] = {title = "Capo Moderatore", color = Color3.fromRGB(98, 0, 0), mod = true, admin = false, owner = false},
	["212"] = {title = "ViceCapo Moderatore", color = Color3.fromRGB(98, 0, 0), mod = true, admin = false, owner = false},
	["200"] = {title = "Senior Moderatore", color = Color3.fromRGB(117, 0, 0), mod = true, admin = false, owner = false},
	["114"] = {title = "Moderatore", color = Color3.fromRGB(138, 3, 3), mod = true, admin = false, owner = false},
	["110"] = {title = "Junior Moderatore", color = Color3.fromRGB(171, 48, 32), mod = true, admin = false, owner = false},
	["100"] = {title = "Trial Moderatore", color = Color3.fromRGB(171, 73, 43), mod = true, admin = false, owner = false},
	
	
	["1"] = {title = "Membro", color = Color3.fromRGB(159, 135, 58), mod = false, admin = false, owner = false},
	["0"] = {title = "Guest", color = Color3.fromRGB(131, 113, 48), mod = false, admin = false, owner = false}
	
	
}

--Functions

local function addOverhead()
	local player = players:GetPlayerFromCharacter(char)
	
	local head = char:WaitForChild("Head")
	local newtext = nametag:Clone() --Cloning the text.
	local mainFrame = newtext.Frame.Frame
	local visualName = mainFrame.DisplayName
	local visualNameShadow = mainFrame.DisplayNameShadow
	local nametext = mainFrame.PlayerName
	local nametextShadow = mainFrame.PlayerNameShadow
	local ranktext = mainFrame.Rank
	local Icons = mainFrame.Icons
	local AdminIcon = Icons.Admin
	local OwnerIcon  = Icons.Owner
	local PremiumIcon = Icons.Premium
	local ModIcon = Icons.Mod
	
	local humanoid = char:FindFirstChildOfClass("Humanoid")
	local userId = player.UserId
	local rankGroup = player:GetRankInGroup(idGroup)
	
	
	humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
	
	--Main Text
	newtext.Parent = head
	newtext.Adornee = head
	nametext.Text = player.Name --Changes the text to the player's name.
	nametextShadow.Text = player.Name
	
	visualName.Text = player.DisplayName
	visualNameShadow.Text = player.DisplayName
	
	
	--"If" Statements
	
	
	--Check if player name is in the specialNames table
	if player.MembershipType == Enum.MembershipType.Premium then
		PremiumIcon.Visible = true
	end
	ranktext.Text = Roles[tostring(rankGroup)].title
	ranktext.TextColor3 = Roles[tostring(rankGroup)].color
	AdminIcon.Visible = Roles[tostring(rankGroup)].admin
	ModIcon.Visible = Roles[tostring(rankGroup)].mod
	OwnerIcon.Visible = Roles[tostring(rankGroup)].owner
end

addOverhead()
1 Like

a server/normal script can also run in workspace and startercharacterscripts, not only in serverscriptservice

forgot to mention to remove the original script after creating the script in startercharacterscripts

Any errors in the console or so?

copy my code again i forgot to add smth at the end

now it works fine tysm yall! But i still don’t understand why it wouldn’t work before

2 Likes

If I understand correctly, the script that adds the GUI is in the server. Move the code that does that to the client thru a LocalScript, either in StarterCharacterScripts if your GUIs are ResetOnSpawn == true or StarterPlayerScripts if ResetOnSpawn == false (if I’m not mistaken the property is called ResetOnSpawn).

Then, on the server, set the rank of joining players (either with attributes or NumberValues or StringValues etc.) so that the client can read and interpret it.

Also, I advise you pick all the data associated with how each rank looks (big ranks are shiny and small ranks aren’t whatever whatever) and store it in a ModuleScript right below the LocalScript mentioned in paragraph 1. No reason to keep them in the server as the server won’t render any GUIs (it isn’t a player).