Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you make a hide player name script that only hides local players name?

Asked by 7 years ago

So I tried putting this in a local script that was inside a starter gui button

hid = false function toggle() if hid == false then game.Players.LocalPlayer.HealthDisplayDistance = 0 game.Players.LocalPlayer.NameDisplayDistance = 0 script.Parent.Text = "Hide Name" hid = true elseif hid == true then game.Players.LocalPlayer.HealthDisplayDistance = 100 game.Players.LocalPlayer.NameDisplayDistance = 100 script.Parent.Text = "Show Name" hid = false end end script.Parent.MouseButton1Click:connect(toggle)

but when a player clicks on it then it toggles EVERYONES name.. not just the player that clicked it.

2 answers

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

i'm assuming that you're talking about the client hiding everyone else's names. To do this first we need to turn on FilteringEnabled, then we will create a localscript to run on the client.

Inside the localscript we will use a for loop to run through each player and hide their nametag

for _,v in pairs(game.Players:GetChildren()) do
    v.HealthDisplayDistance=0
    v.NameDisplayDistance=0
end

Next let's add this to your script. I'm going to combine where you call the script and where its ran

local hid = false 
script.Parent.MouseButton1Click:connect(function()
    if hid == false then 
        game.Players.LocalPlayer.HealthDisplayDistance = 0 game.Players.LocalPlayer.NameDisplayDistance = 0 
        script.Parent.Text = "Hide Name" 
        hid = true 
    elseif hid == true then 
        game.Players.LocalPlayer.HealthDisplayDistance = 100 game.Players.LocalPlayer.NameDisplayDistance = 100 
        script.Parent.Text = "Show Name" 
        hid = false 
    end 
end)

Let' change the part where it hides the nametags

local hid = false 
script.Parent.MouseButton1Click:connect(function()
    if hid == false then 
        for _,v in pairs(game.Players:GetChildren()) do
            v.HealthDisplayDistance=0
            v.NameDisplayDistance=0
        end 
        script.Parent.Text = "Hide Name" 
        hid = true 
    elseif hid == true then 
        for _,v in pairs(game.Players:GetChildren()) do
            v.HealthDisplayDistance=100
            v.NameDisplayDistance=100
        end 
        script.Parent.Text = "Show Name" 
        hid = false 
    end 
end)

So remember, make sure filteringenabled is one and this is a localscript

0
lol i was confused on what he was talking about CardboardedCharacter 53 — 7y
0
Thanks this worked great NeitoAkahara 2 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

First of all, be sure to put your code in Code Block.

Secondly, you need to locate the player that is clicking this, not just a random one from the server. An easy way is doing "script.Parent..." all the way up until it gets to the Player.

Example:

hid = false function toggle()

if hid == false then
local Plyr = script.Parent.Parent.Parent.Parent.Parent --Add or Remove Parent to find the Player
Plyr.HealthDisplayDistance = 0 
Plyr.NameDisplayDistance = 0 
script.Parent.Text = "Hide Name" 
hid = true 

elseif hid == true then
local Plyr = script.Parent.Parent.Parent.Parent.Parent --Add or Remove Parent to find the Player
Plyr.HealthDisplayDistance = 100 
Plyr.NameDisplayDistance = 100 
script.Parent.Text = "Show Name" 
hid = false 

end 
end 

script.Parent.MouseButton1Click:connect(toggle)

Hope it worked.

Answer this question