Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my namehide GUI not working right?

I tried making a script where there is a text button that hides your name and health when you click it so others can't see it. I'm pretty sure I did the text button fine because it shows up where I want it and has the right Color. On the other hand I'm not sure what's up with getting your name to hide. When I tested it with my brother It hides the name, but every ones name, Not just the one who clicks on it. I what to know what I can do to fix it, an explanation/advice and what's wrong. here's the script.

Value = Instance.new("BoolValue")
	Value.Parent = script.Parent
	Value.Value = false

	--this is where the textbutton and screengui code is I thought I'd take it out because this part would work
	
textbutton.MouseButton1Down:connect(function()
	if Value.Value == false then 
		game.Players.LocalPlayer.HealthDisplayDistance = 0    
		game.Players.LocalPlayer.NameDisplayDistance = 0
		textbutton.BackgroundColor3 = Color3.new(255, 45/255, 0/255)
		textbutton.Text = "Name Hidden"
		Value.Value = true
	elseif Value.Value == true then
		game.Players.LocalPlayer.HealthDisplayDistance = 100
		game.Players.LocalPlayer.NameDisplayDistance = 100
		textbutton.BackgroundColor3 = Color3.new(100/255, 255/255, 50/255)
		textbutton.Text = "Hide Name"
		Value.Value = false
	end
end)	

-- I think I messed up with LocalPlayer I'm having trouble with the definition of it.

Thank you for reading this I am not great at scripting or Grammar.

1 comment

0

Thank you for answering my question you were pretty helpful, it took me a while to choose which one answered because I wasn't sure they were working. I'm also glad to know a little more about namedisplaydistance and LocalPlayer. :)

3 answers

✓ Accepted answer

The property HealthDisplayDistance and NameDisplayDistance change how far you can see other player's names, not how far other player's see your name.

The only way I know how to do this is an old hacky method where you make your player's head invisible and put a fake head in it's place.

local player = game.Players.LocalPlayer
local nameVisible = true

function HideName()
	if player.Character then
		local fakeHead = player.Character.Head:Clone()
		local weld = Instance.new("ManualWeld")
		fakeHead.Name = "FakeHead"
		fakeHead.Parent = player.Character
		weld.Part0 = player.Character.Head
		weld.Part1 = player.Character.FakeHead
		weld.Parent = player.Character.FakeHead
		player.Character.Head.Transparency = 1
	end
end

function ShowName()
	if player.Character and player.Character.FakeHead then
		player.Character.FakeHead:Destroy()
		player.Character.Head.Transparency = 0
	end
end

textbutton.MouseButton1Down:connect(function()
	if nameVisible then
		HideName()
		textbutton.BackgroundColor3 = Color3.new(255, 45/255, 0/255)
		textbutton.Text = "Name Hidden"
		nameVisible = false
	else
		ShowName()
		textbutton.BackgroundColor3 = Color3.new(100/255, 255/255, 50/255)
		textbutton.Text = "Hide Name"
		nameVisible = true
	end
end)
Value = Instance.new("BoolValue")
    Value.Parent = script.Parent
    Value.Value = false
---If it's set to LocalPlayer it will display everyones health and name to 0.
---Because that property is like the only one that can set everyone's to zero.
---I suggest creating a event and use player
---Here lets make one
game.Players.PlayerAdded:connect(function(player)
textbutton.MouseButton1Down:connect(function()
    if Value.Value == false then 
       player.HealthDisplayDistance = 0    
       player.NameDisplayDistance = 0
        textbutton.BackgroundColor3 = Color3.new(255, 45/255, 0/255)
        textbutton.Text = "Name Hidden"
        Value.Value = true
    elseif Value.Value == true then
       player.HealthDisplayDistance = 100
    	player.NameDisplayDistance = 100
        textbutton.BackgroundColor3 = Color3.new(100/255, 255/255, 50/255)
        textbutton.Text = "Hide Name"
        Value.Value = false
    end
end)    
end)
--Accept this answer if it helped I simply changed client to server sided. So it does not confuse the property with client-sided.

What you're doing is trying to set their name/healthviewdistance to 0, which simply makes it so that the player can't see any names at all.

What you want to do instead is set their head's transparency to 0 and make a "fake head" so that their nametag disappears. This is because if a player's head is transparent then their name does not show up. However, this means that it would look like the player doesn't have a head! To fix this, we just clone the head and weld it.

Here's the code you'll want -

local player = game.Players.LocalPlayer
local hidden = false-- this is the bool I used to check if your name is hidden
script.Parent.MouseButton1Down:connect(function()
if hidden == false then
    local fakeHead = player.Character.Head:Clone() --you're cloning the head here
    fakeHead.Name = "FakeHead"
	fakeHead.Parent = player.Character
    player.Character.Head.Transparency = 1 -- this is where you hide the name.
    player.Character:WaitForChild("FakeHead")
    local weld = Instance.new("Weld") -- welding it so it doesn't fall off :)
    weld.Parent = player.Character.Head
    weld.Part0 = player.Character.Head
    weld.Part1 = player.Character.FakeHead
	script.Parent.TextStrokeColor3 = Color3.new(170/255,0/255,0/255)
	script.Parent.Text = "Show name" -- giving feedback
	hidden = true
else if hidden == true then
	player.Character.Head.Transparency = 0 -- showing the name
	player.Character:FindFirstChild("FakeHead"):Destroy() -- destroying the fake head
	script.Parent.TextStrokeColor3 = Color3.new(156/255,156/255,156/255)
	script.Parent.Text = "Hide name" -- giving feedback
	hidden = false

end
end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.