How To Fix A Tag

I am trying to make a team changer where you hit the job and ui pop up. Then if you hit get tag it. switches your team to that job.

All of this works accept the tag does not change. How do I fix this?
This is what happens in the video

This script is a normal script in StarterCharacterScripts

local char = script.Parent
local plr = game.Players:GetPlayerFromCharacter(char)

local NameTagClone = game.ServerStorage.HeadUI:Clone()

NameTagClone.Parent = char.Head
NameTagClone.Adornee = char.Head

NameTagClone.UI.NameUI.NameName.Text = char.Name

if plr.Team == nil then
	NameTagClone.UI.RankUI.RankName.Text = "Player"
end

repeat wait() until plr.Team ~= nil

NameTagClone.UI.RankUI.RankName.Text = plr.Team.Name

char.Humanoid.DisplayDistanceType = "None"
8 Likes

You have to update the tag after the team changes.
try using

player:GetPropertyChangedSignal("Team"):Connect(function()
   NameTagClone.UI.RankUI.RankName.Text = plr.Team.Name
end)
4 Likes

That did not work

local char = script.Parent

local plr = game.Players:GetPlayerFromCharacter(char)

local NameTagClone = game.ServerStorage.HeadUI:Clone()

NameTagClone.Parent = char.Head
NameTagClone.Adornee = char.Head

NameTagClone.UI.NameUI.NameName.Text = char.Name

if plr.Team == nil then
	NameTagClone.UI.RankUI.RankName.Text = "Player"
end

repeat wait() until plr.Team ~= nil

NameTagClone.UI.RankUI.RankName.Text = plr.Team.Name

char.Humanoid.DisplayDistanceType = "None"

plr:GetPropertyChangedSignal("Team"):Connect(function()
	NameTagClone.UI.RankUI.RankName.Text = plr.Team.Name
end)
3 Likes

You can just change it constantly then.
change

plr:GetPropertyChangedSignal("Team"):Connect(function()

with

game:GetService("RunService").Heartbeat:Connect(function()
2 Likes

Here is what happens when I hit the spawn point it works but when I hit the UI the Tag does not change

1 Like

Could you show us the code responsible of prompting the UI (the .touched event)?

1 Like
local TeamAN = "Animator"

local Job = script.Parent

local Animator = Job.AnimatorFrame

local AnimatorB = Job.AnimatorFrame.AcceptButton

AnimatorB.MouseButton1Down:Connect(function()
	Animator.Visible = not Animator.Visible
end)


AnimatorB.MouseButton1Down:Connect(function(h)
	local player = game.Players.LocalPlayer
	if player then
		player.Team = game:GetService("Teams")[TeamAN]
	end
end)
1 Like

This is the touch script

local Animator = game.Workspace.Map.Jobs.HitBoxes:WaitForChild("Animator")

Animator.Touched:Connect(function(Hit)
	if Hit.Parent:FindFirstChild("Humanoid") then
		script.Parent.Parent.JobUI.AnimatorFrame.Visible = true
		repeat task.wait() until (Animator.Position - Hit.Parent.HumanoidRootPart.Position).magnitude >= 12
		script.Parent.Parent.JobUI.AnimatorFrame.Visible = false
	end
end)
1 Like

Add after

player.Team = game:GetService("Teams")[TeamAN]

The following line:

player.HeadUI.UI.RankUI.RankName.Text = plr.Team.Name
1 Like

That did not work--------------

1 Like

Do you have any error on the output?

1 Like

Ya
HeadUI is not a valid member of Player “Players.Cyber_Designer”

1 Like

Modify that line with this one:

player.Head.HeadUI.UI.RankUI.RankName.Text = plr.Team.Name`
1 Like

It said
Head is not a valid member of Player “Players.Cyber_Designer” -

1 Like

I forgot it is the Player, not the Player’s character yet :sweat_smile:
This should be the final working line:

player.Character.Head.HeadUI.UI.RankUI.RankName.Text = plr.Team.Name`
1 Like

Ok it work Thank You!!! but is

player.Character.Head.HeadUI.UI.RankUI.RankName.Text = player.Team.Name

not

player.Character.Head.HeadUI.UI.RankUI.RankName.Text = plr.Team.Name`
2 Likes

Sorry if I was unable to help with this situation but, as I see you are changing the team and ui from the client and it will only appear on the client’s side, not for the whole server. Try using a remote event to fix this.

1 Like

wait how do I do that----------

You don’t need a remote event

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		---> variables
		local NameTagClone = game.ServerStorage.HeadUI:Clone()

		---> main
		NameTagClone.Parent = char.Head
		NameTagClone.Adornee = char.Head

		NameTagClone.UI.NameUI.NameName.Text = char.Name

		if plr.Team == nil then
			NameTagClone.UI.RankUI.RankName.Text = "Player"
		end

		repeat wait() until plr.Team ~= nil

		NameTagClone.UI.RankUI.RankName.Text = plr.Team.Name

		char.Humanoid.DisplayDistanceType = "None"

		game:GetService("RunService").Heartbeat:Connect(function()
			NameTagClone.UI.RankUI.RankName.Text = plr.Team.Name
		end)
	end)
end)

This is very inefficient, why don’t you use the code I gave you?
It is efficient and is also server side, meaning it will show the updated title to all players in the server