How can I hide a player from the Playerlist and Escape Menu?

Hi, I think I mentioned this before, but I am making a rooms recreation on Roblox. In the original, when a player dies, they vanish from the Escape Menu and the tab playerlist, I wrote some code to do it and it seems to work on one client, but not on the other. The player still respawns but their camera is locked and they can’t move on the other player’s side.

here’s the code i wrote for it, it’s in a local script inside of StarterPlayerScripts

game:GetService("RunService").RenderStepped:Connect(function()
	local player = game.Players.LocalPlayer
	local character = player.Character
	local humanoid = character:WaitForChild("Humanoid")
	humanoid.Died:Connect(function()
		player:Destroy()
	end)
end)

any ideas? am I doing something wrong?
Any help is appreciated, thank you in advance

2 Likes

Well the first thing I noticed is that for ever renderstep you connect a new function to humanoid.Died. This can cause a ton of lag and possible errors.
What you could do would be to tell the server fire all clients with a player in the first parameter, and each client would locally call destroy() on that player. You could also just make your own playerlist, which would probably be a lot better.

Edit: In script executer games I have seen people removing themselves from the leaderboard, and I have absolutely no idea how they do it. You might be able to find a server side script that hides a player.

1 Like

i was thinking on remote events at first, though I’m pretty terrible with remote events even though I’ve been scripting for almost a year now

how would i go about that method?

In scripts, you can make yourself disappear by making your player instance’s parent nil.
The script has to be serversided.

1 Like

In a playeradded event you can get the humanoid of the player’s character and connect a humanoid.Died event, then when that player dies use :FireAllClients() on a remote event with the player that died as the parameter, then in the OnClientEvent the player can locally delete the player from the parameter

1 Like

Here’s a working version of a script, obv no anti exploit:

Localscript

local rs = game:GetService("ReplicatedStorage")
local remote = rs.RemovePlayer

--there should be a remote in replicated storage called RemovePlayer 

--the following function will trigger when the player dies
function onDeath()
	remote:FireServer()
end

--this funcion removesthe player
remote.OnClientEvent:Connect(function(plr)
	if plr then
		if plr~=game:GetService("Players").LocalPlayer then --this line stops the player who died from removing themselves.
			if plr.ClassName == "Player" then
				plr:Destroy()
			end
		end
	end
end)

--you can put any form of checking for player death
local c = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.Character:Wait()
local hum = c:WaitForChild("Humanoid")
hum.Died:Connect(onDeath)

Serverscript

local rs = game:GetService("ReplicatedStorage")
local remote = rs.RemovePlayer

remote.OnServerEvent:Connect(function(plr)
	if plr then
		if plr.ClassName == "Player" then
			remote:FireAllClients(plr)
		end
	end
end)
6 Likes

this worked, thank you so so much!

Also, I realized that to prevent exploiters from deleting all the other players you can just handle the deaths on the server.