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

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

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

01local hid = false
02script.Parent.MouseButton1Click:connect(function()
03    if hid == false then
04        game.Players.LocalPlayer.HealthDisplayDistance = 0 game.Players.LocalPlayer.NameDisplayDistance = 0
05        script.Parent.Text = "Hide Name"
06        hid = true
07    elseif hid == true then
08        game.Players.LocalPlayer.HealthDisplayDistance = 100 game.Players.LocalPlayer.NameDisplayDistance = 100
09        script.Parent.Text = "Show Name"
10        hid = false
11    end
12end)

Let' change the part where it hides the nametags

01local hid = false
02script.Parent.MouseButton1Click:connect(function()
03    if hid == false then
04        for _,v in pairs(game.Players:GetChildren()) do
05            v.HealthDisplayDistance=0
06            v.NameDisplayDistance=0
07        end
08        script.Parent.Text = "Hide Name"
09        hid = true
10    elseif hid == true then
11        for _,v in pairs(game.Players:GetChildren()) do
12            v.HealthDisplayDistance=100
13            v.NameDisplayDistance=100
14        end
15        script.Parent.Text = "Show Name"
16        hid = false
17    end
18end)

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:

01hid = false function toggle()
02 
03if hid == false then
04local Plyr = script.Parent.Parent.Parent.Parent.Parent --Add or Remove Parent to find the Player
05Plyr.HealthDisplayDistance = 0
06Plyr.NameDisplayDistance = 0
07script.Parent.Text = "Hide Name"
08hid = true
09 
10elseif hid == true then
11local Plyr = script.Parent.Parent.Parent.Parent.Parent --Add or Remove Parent to find the Player
12Plyr.HealthDisplayDistance = 100
13Plyr.NameDisplayDistance = 100
14script.Parent.Text = "Show Name"
15hid = false
16 
17end
18end
19 
20script.Parent.MouseButton1Click:connect(toggle)

Hope it worked.

Answer this question