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 3 years ago
Edited 3 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:

local player = game.Players.LocalPlayer
        local Character = player.Character
            if Hidden == false then
                player.HealthDisplayDistance = 0
                player.NameDisplayDistance = 0
                Hidden = true
                player.PlayerGui.INFO.NameDi.Text = "Name Hidden: TRUE"
        end

2 answers

Log in to vote
0
Answered by 3 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:

game.ReplicatedStorage.humanoidChange.On`ServerEvent:Connect(function(player)
       game.Players:FindFirstChild(player.Name).Character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
        game.Players:FindFirstChild(player.Name).PlayerGui.ServerInfo.NameDi.Text = "Name Hidden: TRUE"
end)
Ad
Log in to vote
0
Answered by 3 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:

local RP = game:GetService("ReplicatedStorage")
local Event = RP:WaitForChild("RemoteEvent") --The name of your event

local player = game.Players.LocalPlayer
local Character = player.Character or player.CharacterAdded:Wait()

if Hidden == false then
    Hidden = true
    player.PlayerGui.INFO.NameDi.Text = "Name Hidden: TRUE"
    Event:FireServer(Hidden)
end

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

local RP = game:GetService("ReplicatedStorage")
local Event = RP:FindFirstChild("RemoteEvent")

Event.OnServerEvent:Connect(function(player, bool)
    if bool == false then
        player.HealthDisplayDistance = 10--Whatever distance you want when turned on
        player.NameDisplayDistance = 10
        else
        player.HealthDisplayDistance = 0
        player.NameDisplayDistance = 0 
    end
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 : )

Answer this question