--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
It causes a script timeout
This is incorrect.
CharacterAdded works across all scripts.
Ok, thanks for the info, but either way I can’t use it because the player chooses the team via Gui
You can use a RemoteEvent to tell the server that the player has chosen a team. Then assign the team and create the text label above their name.
In a CharacterAdded event you can check if they have a team already. If they do, then create the label.
Like this?
-- 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
1 Like
The problem with my script is that I can’t do multiple teams
@IAmKingMatt @imalex4 @d_vHoodie
Is that what you wanted? The one I made is for multiple teams.
My Mistake it’s
lowertext.TextColor3 = player.TeamColor.Color -- Set text to team color.
Just set text to the color of the player’s team.
How can players be in game before script from ServerScriptService start running.
It’s possible, it’s called redundancy and I’ve experienced problems with not making the for loop on the PlayerAdded.
You can’t use brickcolor for TextColor3
1 Like
When you do BrickColor.Color it returns the Color3 equivalent . (Fun Fact)
1 Like
Well the error is saying it expected a Color3 value, but got BrickColor
If that is the case (people skipping PlayerAdded event) then you would need to do loop for data loading and all other things that include PlayerAdded event.
Edit: after reading other posts related to it I can only find it happening when playing in studio.
Yeah I made a mistake on the last code I posted but I edited it and you must have not seen it. But here it is try this.
lowertext.TextColor3 = player.TeamColor.Color -- Set text to team color.
Hey man I do it when I load data but if it’s hard to believe just look it up.
I can’t seem to find it please provide the link I am very interested in that behaviour.
Here is a forum post on it right here Players joining before Scripts yield?
1 Like