Invisible Other Players On Client Guide
If you want to invisible other people on a client - the code below will do the job!
Code 1 (Open)
local Players = game:GetService("Players")
for _, player in pairs(Players:GetPlayers()) do
if player.Character and player ~= Players.LocalPlayer then
player.Character.Parent = nil
end
end
When ran, the code above will make everyone except for you invisible as soon as your character spawned.
HEY!!!
That doesn’t answer my question! I need a button that you can activate to hide other players, not a bunch of lines thrown to me and let me to figure out. Be patient, we will solve the code’s logic one by one before finishing the actual product:
Question (And answers, obviously)!
What is player.Character and player ~= Players.LocalPlayer
, exactly?
Let’s break down them into two part of logics: player.Character
and player ~= Players.LocalPlayer
.
Logic 1
First, what is player.Character
? You could imagine a dot stands for 's
, which player.Character
could mean player’s Character. But why would you add a if
statement to check that?? Sometimes, if the player’s character is in the void, you will get no returns since how are you supposed to get a destroyed object without magic? So that’s why we use monday.com if
statements to check does it exist or not.
Logic 2
Second, what is player ~= Players.LocalPlayer
? Players.LocalPlayer
is the client that ran the script, which is yourself, so the above statement will check if the player value is not same (~=
) with the player that ran the script, if it’s really yourself, don’t invisible it and vice-versa.
What is player.Character.Parent = nil
?
The code will parent the player.Character to nil so the player will never respawn on the client. If you made a game that is intended to have collisions between each other and you want this feature, this tutorial may not be suitable for you because parenting the player’s character to nil will not make the player character be in the playable bounds (workspace
) so the client will not see the other character and will collide with each other. Either way, you shouldn’t make an invisible player feature in that situation.
Why not destroy the characters so they are “invisible”?
There’s not much explanation but if you destroy the characters you are never going to get the characters back to visible
BACK TO THE TOPIC
Aside from the big text, how to make them back to visible? Huh. You can use the code above but instead of player.Character.Parent = nil
, we parent it to workspace
(the playable bounds).
If you want to visible/invisible other people through a button, you will need a MouseButton1Click
signal to check if it’s clicked or not and a variable for turning it on and off to toggle:
(First, we will set up the MouseButton1Click
signal and we will toggle it on to off or off to on (like a light switch) after activating the button clicked signal, and then we will check if the variable is on or off, if it’s off then invisible everyone excluding the client (player that clicked the button), if it’s on just make everyone visible)
Final code (Open)
--\\ Services
local Players = game:GetService("Players")
--\\ Scopes
local Button = script.Parent
local PlayerHidden = false
--\\ Functions
local function ButtonPressed()
PlayerHidden = not PlayerHidden
-- not true will results false; not false will results true
-- it basically reverses it (PlayerHidden variable)
if PlayerHidden then
for _, player in pairs(Players:GetPlayers()) do
if player.Character and player ~= Players.LocalPlayer then
player.Character.Parent = nil
end
end
else
for _, player in pairs(Players:GetPlayers()) do
if player.Character and player ~= Players.LocalPlayer then
player.Character.Parent = workspace
end
end
end
end
--\\ Connections
Button.MouseButton1Click:Connect(ButtonPressed)
The explorer tree will be like this to have the final code works:

or

or whatever! As long as the script is parented inside the button you want the player to press for the player to be visible/invisible
If you followed the steps and read through them carefully you might understand the concept, if not maybe you have to read again or reply me!
The script will not be 100% efficient or 100% correct or the best way possible, but it’s a method that is clean
(I won’t explain everything one by one because this post will be too long, you might need some coding basis if you want to understand what’s going on from the script or what alien language I am speaking as I already explained the concept and the rest is just setups or stuffs)
alright bye 