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

Current player's name not hiding?

Asked by 4 years ago
Edited 4 years ago

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:

1local 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

2 answers

Log in to vote
0
Answered by 4 years ago

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:

1game.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"
4end)
Ad
Log in to vote
0
Answered by 4 years ago

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:

01local RP = game:GetService("ReplicatedStorage")
02local Event = RP:WaitForChild("RemoteEvent") --The name of your event
03 
04local player = game.Players.LocalPlayer
05local Character = player.Character or player.CharacterAdded:Wait()
06 
07if Hidden == false then
08    Hidden = true
09    player.PlayerGui.INFO.NameDi.Text = "Name Hidden: TRUE"
10    Event:FireServer(Hidden)
11end

and now add a Script in ServerScriptService and put in the following:

01local RP = game:GetService("ReplicatedStorage")
02local Event = RP:FindFirstChild("RemoteEvent")
03 
04Event.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
12end)

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 : )

Answer this question