I’m attempting to make all players locally invisible/cancollidable so that multiple people can use the same lobby at once. Does anyone know how I would achieve this? I found a post similar to this and used some code I found (I DID NOT WRITE THIS!):
local hide = true
local function checkPart(part)
for a,b in pairs(part:GetChildren()) do
checkPart(b)
end
if part:IsA("BasePart") or part:IsA("Decal") then
if hide then
part.Transparency = 1
end
end
end
local players = game:GetService("Players")
local localPlayer = players.LocalPlayer
game:GetService("RunService").RenderStepped:Connect(function()
for i,v in pairs(players:GetPlayers()) do
if v ~= localPlayer then
local char = v.Character
if char then
checkPart(char)
end
end
end
end)
The issue with this code is that it makes all players transparent, but when I try to add part.CanCollide = false it doesn’t work. Does anyone know how to make all players cancollided, but all players other than the local player transparent?
Collisions are hacked on every frame against a character’s Head, Torso and HumanoidRootPart. It is required that these parts of the character have collisions enabled because they’re used internally when performing raycasts to keep the Humanoid on top of a surface.
If you want characters to be able to walk through each other, apply collision filtering. As for the invisibility, simply use GetDescendants and set the transparency of any BasePart to 1. Do not use a recursive function unnecessarily and do not use RenderStepped for non camera-bound updates.
Adding a rough code sample for transparency.
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local function hideCharacter(character)
for _, part in ipairs(character:GetChildren()) do
if part:IsA("BasePart") then
part.Transparency = 1
end
end
end
for _, player in ipairs(Players:GetPlayers()) do
if player ~= LocalPlayer and player.Character then
hideCharacter(player.Character)
end
end
You might want to use LocalTransparencyModifier instead of Transparency for this, as it doesn’t change the Transparency, so the original transparency remains intact, but they will still appear invisible this way
Feel free to DM me if this is the case, but I encourage you to do your own debugging and research first to confirm if what you did is legal by the engine or not. The only way I can see that code not working is either if I myself made a mistake in writing it or your implementation is faulty. That being said, you should also provide details if something doesn’t work so the issue can be quicker resolved: if you don’t include those details, then I have to ask and the process gets extended.