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
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
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.