So, I am trying to make a system where if the localplayer presses Q then it hides his/her name.
However, it's not hiding his/her name from other players, instead it's hiding other player's name not the current players;
LOCAL SCRIPT:
1 | local player = game.Players.LocalPlayer |
2 | local Character = player.Character |
3 | if Hidden = = false then |
4 | player.HealthDisplayDistance = 0 |
5 | player.NameDisplayDistance = 0 |
6 | Hidden = true |
7 | player.PlayerGui.INFO.NameDi.Text = "Name Hidden: TRUE" |
8 | end |
U need to use remote events if u want that the username is hidden for all players. the server script should look a lil like this:
1 | game.ReplicatedStorage.humanoidChange.On`ServerEvent:Connect( function (player) |
2 | game.Players:FindFirstChild(player.Name).Character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None |
3 | game.Players:FindFirstChild(player.Name).PlayerGui.ServerInfo.NameDi.Text = "Name Hidden: TRUE" |
4 | end ) |
You need to use a RemoteEvent to communicate with from client to server
So first add a RemoteEvent in ReplicatedStorage
Now in your LocalScript put in the following:
01 | local RP = game:GetService( "ReplicatedStorage" ) |
02 | local Event = RP:WaitForChild( "RemoteEvent" ) --The name of your event |
03 |
04 | local player = game.Players.LocalPlayer |
05 | local Character = player.Character or player.CharacterAdded:Wait() |
06 |
07 | if Hidden = = false then |
08 | Hidden = true |
09 | player.PlayerGui.INFO.NameDi.Text = "Name Hidden: TRUE" |
10 | Event:FireServer(Hidden) |
11 | end |
and now add a Script in ServerScriptService and put in the following:
01 | local RP = game:GetService( "ReplicatedStorage" ) |
02 | local Event = RP:FindFirstChild( "RemoteEvent" ) |
03 |
04 | Event.OnServerEvent:Connect( function (player, bool) |
05 | if bool = = false then |
06 | player.HealthDisplayDistance = 10 --Whatever distance you want when turned on |
07 | player.NameDisplayDistance = 10 |
08 | else |
09 | player.HealthDisplayDistance = 0 |
10 | player.NameDisplayDistance = 0 |
11 | end |
12 | end ) |
Didn't test it but it should work unless there was a typo, if there are any errors just tell me and I'll correct them : )