So basically I wanted to create a name tag based on the team you are in. Ex: player: JohnDoe team: Blue that mean he will have a nametag below his player name, that says ‘blue’. I have already attempted at trying this, and no errors, but the doesn’t work
-- Serverscript in serverscriptservice
--Variables
local rep = game:GetService("ReplicatedStorage")
local nametag = rep.NameTag
--Functions
for _, player in pairs(game.Players:GetPlayers()) do
local char = player.Character
--Varibles
local head = char.Head
local newtext = nametag:Clone() --Cloning the text.
local uppertext = newtext.UpperText
local lowertext = newtext.LowerText
local humanoid = char.Humanoid
humanoid.DisplayDistanceType = "None"
--Main Text
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = player.Name --Changes the text to the player's name.
--"If" Statements
if player.Team.Name == "Joe Team" then
lowertext.Text = "Joe Team" --This is that the text will say.
lowertext.TextColor3 = Color3.fromRGB(255, 51, 0) --This is what the color of the text will be.
end
end
Also, are you running this right when the game starts? It probably won’t work, as the players won’t be loaded so nothing will happen. Try using CharacterAdded.
Yep I have a thing called in rep, and I want this to loop every sec, I can figure that out
EDIT:
--Variables
local rep = game:GetService("ReplicatedStorage") --You can change this to ServerStorage for more security.
local nametag = rep.NameTag
while true do
--Functions
for _, player in pairs(game.Players:GetPlayers()) do
local char = player.Character
--Varibles
local head = char.Head
local newtext = nametag:Clone() --Cloning the text.
local uppertext = newtext.UpperText
local lowertext = newtext.LowerText
local humanoid = char.Humanoid
humanoid.DisplayDistanceType = "None"
--Main Text
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = player.Name --Changes the text to the player's name.
--"If" Statements
--You can add as many of these as you wish, just change it to the player's name.
if player.Team.Name == "Joe Team" then
lowertext.Text = "Joe Team" --This is that the text will say.
lowertext.TextColor3 = Color3.fromRGB(255, 51, 0) --This is what the color of the text will be.
end
wait(2)
end
end
--Variables
local rep = game:GetService("ReplicatedStorage") --You can change this to ServerStorage for more security.
local nametag = rep.NameTag
while true do
--Functions
for _, player in pairs(game.Players:GetPlayers()) do
local char = player:WaitForChild("Character")
--Varibles
local head = char.Head
local newtext = nametag:Clone() --Cloning the text.
local uppertext = newtext.UpperText
local lowertext = newtext.LowerText
local humanoid = char.Humanoid
humanoid.DisplayDistanceType = "None"
--Main Text
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = player.Name --Changes the text to the player's name.
--"If" Statements
--You can add as many of these as you wish, just change it to the player's name.
if player.Team.Name == "Joe Team" then
lowertext.Text = "Joe Team" --This is that the text will say.
lowertext.TextColor3 = Color3.fromRGB(255, 51, 0) --This is what the color of the text will be.
end
wait(2)
end
end
-- serverscript in serverscriptservice
--Variables
local rep = game:GetService("ReplicatedStorage") --You can change this to ServerStorage for more security.
local nametag = rep.NameTag
-- functions
game.ReplicatedStorage.GoToJoeTeam.OnServerEvent:Connect(function(player)
--Varibles
local char = player.Character
local head = char.Head
local newtext = nametag:Clone() --Cloning the text.
local uppertext = newtext.UpperText
local lowertext = newtext.LowerText
local humanoid = char.Humanoid
humanoid.DisplayDistanceType = "None"
--Main Text
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = player.Name --Changes the text to the player's name.
--"If" Statements
--You can add as many of these as you wish, just change it to the player's name.
if player.Team.Name == "Joe" then
lowertext.Text = "Joe" --This is that the text will say.
lowertext.TextColor3 = Color3.fromRGB(255, 51, 0) --This is what the color of the text will be.
end
end)
-- local script in gui button
script.Parent.MouseButton1Click:Connect(function()
game.ReplcatedStorage.GoToJoeTeam:FireServer()
end)
I feel like this a much simpler way to do it. It assigns your team not just a specific team and correct me if I’m wrong but you want it to display the players team so I came up with this.
--// Services
local players = game:GetService("Players")
local replicatedStorage = game:GetService("ReplicatedStorage")
--// Assets
local nametag = replicatedStorage.NameTag
--// Apply Name Tag
local function SetNameTag(player)
local char = player.Character
local head = char.Head
local newtext = nametag:Clone() -- Get new name tag
local uppertext = newtext.UpperText
local lowertext = newtext.LowerText
local humanoid = char.Humanoid
humanoid.DisplayDistanceType = "None"
--// Name Tag
newtext.Parent = head
newtext.Adornee = head
uppertext.Text = player.Name -- Set text to players name
--// Set Text
lowertext.Text = player.Team.Name -- Set text to team name.
lowertext.TextColor3 = player.TeamColor.Color -- Set text to team color.
end
--// Player Added
players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
SetNameTag(player)
end)
end)
--// For players already in game.
for _, player in pairs(players:GetPlayers()) do
if (player.Character) then
SetNameTag(player)
end
end