Basically, just like any major devs have recommended, hiding players from a client locally is best when putting all players in a different location and then returning them back on request.
However, as much as it should only affect the client side, it apparently causes issues on the server as well. Players seem to randomly render invisible for players who join and don’t even have the hide feature enabled.
Note that the script is a LocalScript on a client and has no connections to the server. There isn’t any other script that connects to the character.
Code:
for i,v in pairs(game.Players:GetChildren()) do
if v.Name ~= player.Name then
v.Character.Parent = ReplicatedStorage.HiddenPlayers
end
end
Hmm. When does your code execute? Do you use a RemoteEvent to tell the client to hide the players? One last request, may you share a gif with me so I can understand the issue more properly? Thank you.
Alright. The code itself looks alright. Do you receive any error in the output once the code executes? Also, when do you take their characters back into the workspace? Unless you keep them in ReplicatedStorage the whole time.
Was bored so I decided to write an entire system for this.
--LOCAL
local Replicated = game:GetService("ReplicatedStorage")
local HideAll = Replicated:WaitForChild("HideAll")
local ShowAll = Replicated:WaitForChild("ShowAll")
local CharacterAdded = Replicated:WaitForChild("CharacterAdded")
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local Button = script.Parent
local Toggle = false
local function HideCharacterRecursive(Object)
for _, Child in ipairs(Object:GetChildren()) do
if Child:IsA("BasePart") then
Child.Transparency = 1
HideCharacterRecursive(Child)
elseif Child:IsA("Accessory") then
HideCharacterRecursive(Child)
elseif Child:IsA("Decal") then
Child.Transparency = 1
end
end
end
local function ShowCharacterRecursive(Object)
for _, Child in ipairs(Object:GetChildren()) do
if Child:IsA("BasePart") then
if Child.Name ~= "HumanoidRootPart" then
Child.Transparency = 0
end
ShowCharacterRecursive(Child)
elseif Child:IsA("Accessory") then
ShowCharacterRecursive(Child)
elseif Child:IsA("Decal") then
Child.Transparency = 0
elseif Child:IsA("Humanoid") then
Child.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.Subject
end
end
end
local function OnButtonClicked()
Toggle = not Toggle
if Toggle then
HideAll:FireServer()
for _, Player in ipairs(Players:GetPlayers()) do
if LocalPlayer ~= Player then
local Character = Player.Character
HideCharacterRecursive(Character)
end
end
elseif not Toggle then
ShowAll:FireServer()
for _, Player in ipairs(Players:GetPlayers()) do
if LocalPlayer ~= Player then
local Character = Player.Character
ShowCharacterRecursive(Character)
end
end
end
end
local function OnCharacterAdded(Character)
HideCharacterRecursive(Character)
end
Button.MouseButton1Click:Connect(OnButtonClicked)
CharacterAdded.OnClientEvent:Connect(OnCharacterAdded)
--SERVER
local Players = game:GetService("Players")
local Run = game:GetService("RunService")
local Replicated = game:GetService("ReplicatedStorage")
local HideAll = Replicated.HideAll
local ShowAll = Replicated.ShowAll
local CharacterAdded = Replicated.CharacterAdded
local OtherPlayersInvisible = {}
local function OnHideAllFired(Player)
table.insert(OtherPlayersInvisible, Player)
end
local function OnShowAllFired(Player)
table.remove(OtherPlayersInvisible, table.find(OtherPlayersInvisible, Player))
end
local function OnPlayerAdded(Player)
local function OnCharacterLoaded(Character)
Run.Heartbeat:Wait()
for _, TablePlayer in ipairs(OtherPlayersInvisible) do
if TablePlayer ~= Player then
CharacterAdded:FireClient(TablePlayer, Character)
end
end
end
Player.CharacterAppearanceLoaded:Connect(OnCharacterLoaded)
end
local function OnPlayerRemoving(Player)
local TablePlayer = table.find(OtherPlayersInvisible, Player)
if TablePlayer then
table.remove(OtherPlayersInvisible, TablePlayer)
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
HideAll.OnServerEvent:Connect(OnHideAllFired)
ShowAll.OnServerEvent:Connect(OnShowAllFired)
The local script goes inside a TextButton/ImageButton GuiObject (which acts as a toggle button), the server script goes inside “ServerScriptService” and 3 RemoteEvent instances are required (all parented to the ReplicatedStorage folder) named; HideAll, ShowAll & CharacterAdded.
It has been thoroughly tested and everything works great (in my opinion).
If you need assistance/anything explained feel free to reach out.