local function SetNameTag(active)
local Character = Player.Character
if not Character then return end
Character.Head.NameTag.Enabled = active
end
print(1)
SetNameTag(false)
As I can see in the output, print('Disabling') isn’t printing Disabling, probably because the Character didn’t load yet, and thus the if not Character then return end just returned and the function stopped without disabling the UI.
To avoid this problem simlply add a small wait before calling the function. It does make sense to use player.CharacterAdded:Wait(), but really this problem here will only happen if the function is called before the character was loaded, which I doubt will happen when an actual player plays the game, so it’s just for testing purposes.
local function SetNameTag(active)
local Character = Player.Character
if not Character then return end
print('Disabling')
Character.Head.NameTag.Enabled = active
end
wait(2)
SetNameTag(false)
That’s a pretty simple fix, you can change the text of the textlabel to nothing instead so it doesn’t display.
Example:
local Character = Player.Character;
if not Character then return end;
if active then
Character.Head.NameTag.Textlabel.Text = "Leader";
else
Character.Head.NameTag.Textlabel.Text = "";
end;
end;
I’m sorry, I wasn’t thinking straight. Here’s a solution that is optimal.
SOLUTION:
local function setNameTag(active)
local Character = Player.Character;
if Character then return end;
print("Disabling!")
Character.Head.NameTag.TextLabel.Visible = active;
end;
This looks like the script would fire when a player just joined the game, so maybe its because the character wasn’t fully loaded in yet(local scripts tend to not find the character when a player joins the game).
So I would change it:
local function SetNameTag(active)
local Character = Player.Character
if not Character then Character = Player.CharacterAdded:Wait() -- waits until the character is added
print('Disabling')
Character.Head.NameTag.Enabled = active
end
print(1)
SetNameTag(false)
You can see that the enabled is still “true”. My only guess at this point is “ResetOnSpawn” is equal to true. Try ticking that to false and see what happens.
Do not try to do sorts of “active” and “unactive”.
I’ve fixed your code now. There is the code:
local function SetNameTag(active)
local Character = Player.Character
if not Character then return end
print('Disabling')
Character.Head.NameTag.Enabled = true
end
print(1)
SetNameTag(false)
This seems very much like a bug. I can’t reproduce it in a blank baseplate with the exact same properties on the BillboardGui. Try it in a live game. Try it in Test Server. If it continues with those, then something very very strange is going on.
If this Gui exists on the server, try having it disabled on the server and enabled on each client to see if it’s any different. Either way this is a bug. Enabled should have executive control over whether the Gui renders or not.