Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Current player's name not hiding?

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

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)

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

This discussion is preserved as it was. New answers, comments, and votes are closed.