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.
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
1 | for _,v in pairs (game.Players:GetChildren()) do |
2 | v.HealthDisplayDistance = 0 |
3 | v.NameDisplayDistance = 0 |
4 | end |
Next let's add this to your script. I'm going to combine where you call the script and where its ran
01 | local hid = false |
02 | script.Parent.MouseButton 1 Click: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 |
12 | end ) |
Let' change the part where it hides the nametags
01 | local hid = false |
02 | script.Parent.MouseButton 1 Click: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 |
18 | end ) |
So remember, make sure filteringenabled is one and this is a localscript
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:
01 | hid = false function toggle() |
02 |
03 | if hid = = false then |
04 | local Plyr = script.Parent.Parent.Parent.Parent.Parent --Add or Remove Parent to find the Player |
05 | Plyr.HealthDisplayDistance = 0 |
06 | Plyr.NameDisplayDistance = 0 |
07 | script.Parent.Text = "Hide Name" |
08 | hid = true |
09 |
10 | elseif hid = = true then |
11 | local Plyr = script.Parent.Parent.Parent.Parent.Parent --Add or Remove Parent to find the Player |
12 | Plyr.HealthDisplayDistance = 100 |
13 | Plyr.NameDisplayDistance = 100 |
14 | script.Parent.Text = "Show Name" |
15 | hid = false |
16 |
17 | end |
18 | end |
19 |
20 | script.Parent.MouseButton 1 Click:connect(toggle) |
Hope it worked.