So basically my friend made a really cool movement system for my game but the name tags aren’t there anymore so its hard to tell which team someone is on, but it doesn’t seem to want to work, the color just stays as the default circle color.
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local function onCharacterAdded(character, plr)
RunService.Stepped:Wait()
local billboard = game.ReplicatedStorage.BillboardGui:Clone()
billboard.Parent = character.Head
billboard.Enabled = true
--[[ while true do
if plr.Team == "Taggers" then
billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
elseif plr.Team == "Safe" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
elseif plr.Team == "Survivor" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
end--]]
end
game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
plr.CharacterAdded:Connect(onCharacterAdded)
local Character = plr.CharacterAdded:Wait()
local billboard = plr.Character.Head.BillboardGui
while true do
if plr.Team == "Taggers" then
billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
elseif plr.Team == "Safe" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
elseif plr.Team == "Survivor" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
end
end
wait(3) -- waits just in case player isn't loaded -- makes it visible
end)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local function onCharacterAdded(character, plr)
RunService.Stepped:Wait()
local billboard = game.ReplicatedStorage.BillboardGui:Clone()
billboard.Parent = character.Head
billboard.Enabled = true
--[[ while true do
task.wait()
if plr.Team == "Taggers" then
billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
elseif plr.Team == "Safe" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
elseif plr.Team == "Survivor" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
end--]]
end
game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
plr.CharacterAdded:Connect(onCharacterAdded)
local Character = plr.CharacterAdded:Wait()
local billboard = plr.Character.Head.BillboardGui
while true do
if plr.Team == "Taggers" then
billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
elseif plr.Team == "Safe" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
elseif plr.Team == "Survivor" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
end
end
wait(3) -- waits just in case player isn't loaded -- makes it visible
end)
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local function onCharacterAdded(character, plr)
RunService.Stepped:Wait()
local billboard = game.ReplicatedStorage.BillboardGui:Clone()
billboard.Parent = character.Head
billboard.Enabled = true
--[[ while true do
task.wait()
if plr.Team == "Taggers" then
billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
elseif plr.Team == "Safe" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
elseif plr.Team == "Survivor" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
end--]]
end
game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
plr.CharacterAdded:Connect(onCharacterAdded)
local Character = plr.CharacterAdded:Wait()
local billboard = game.ReplicatedStorage.BillboardGui:Clone()
billboard.Parent = Character.Head
while wait() do
if plr.Team.Name == "Taggers" then
billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
elseif plr.Team.Name == "Safe" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
elseif plr.Team.Name == "Survivor" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
end
end
wait(3) -- waits just in case player isn't loaded -- makes it visible
end)
Ok, I think I got it.
Comment the line plr.CharacterAdded:Connect(onCharacterAdded).
Then, in the same function, after billboard.Parent = Character.Head, write billboard.Enabled = true.
Alright, remove the top function and replace the bottom one with this:
game.Players.PlayerAdded:Connect(function(plr) -- Insert your name in between the ""
plr.CharacterAdded:Connect(function(Character)
local billboard = game.ReplicatedStorage.BillboardGui:Clone()
billboard.Parent = Character.Head
billboard.Enabled = true
while wait() do
if plr.Team.Name == "Taggers" then
billboard.ImageLabel.ImageColor3 = Color3.new(255, 0, 0)
elseif plr.Team.Name == "Safe" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.419608, 0.196078, 0.486275)
elseif plr.Team.Name == "Survivor" then
billboard.ImageLabel.ImageColor3 = Color3.new(0.960784, 0.803922, 0.188235)
end
end
end)
end)
The current solution you have is extraordinarily inefficient. This is because you are using an infinite loop. The player can stay on the same team for a long time, but regardless, this code will continue to run every heartbeat (frame). Roblox has built-in methods which help to solve a problem like this. Rather than loop infinitely checking for the team, set the team initially, and then bind a function to a changed event.
Here is an example:
--Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Variables
local billboard = ReplicatedStorage:WaitForChild("BillboardGui")
--Functions
--Player Added
local function onPlayerAdded(plr)
--Definining the function here so it is within the scope to use the plr variable
local function onCharacterAdded(char)
local bb = billboard:Clone() --Clone the billboard GUI
bb.Parent = char --Parenting it to the player's character
--For changing the billboard color
local function updateBBColor()
bb.ImageColor3 = plr.Team.TeamColor.Color or Color3.fromRGB(255, 255, 255) --The team color, or white
end
--Binding the player's team changing
plr:GetPropertyChangedSignal("Team"):Connect(updateBBColor)
end
--In case the player's character is already loaded
if plr.Character then
onCharacterAdded(plr.Character)
end
--Binding the character added
plr.CharacterAdded:Connect(onCharacterAdded)
end
--Events
Players.PlayerAdded:Connect(onPlayerAdded)
Let me know if this does not work, I can make adjustments.