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

How do you make players invisible when they join the game?

I have asked on the discord and gotten some help with code snippets but I have not been successful so far.

game.Players.PlayerAdded:Connect(function(character)	
local function set_transparency(instance, transparency)
    for _, v in pairs(instance:GetDescendants()) do
        if v:IsA("BasePart") or v:IsA("Decal") or v:IsA("GuiBase3d") then
            v.Transparency = transparency
        end
    end
end
set_transparency(character, 1)
end)

1 comment

1

PlayerAdded is for when they join the game CharacterAdded is when the character spawns in tge game

2 answers

✓ Accepted answer

Your function works, you just need to input the character (not the player). This has a super simple fix:

local function set_transparency(model, transparency)
    for _, v in pairs(model:GetDescendants()) do
        if v:IsA("BasePart") or v:IsA("Decal") or v:IsA("GuiBase3d") then
            v.Transparency = transparency
        end
    end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		set_transparency(character, 1)
	end)
end)

You would just connect to the CharacterAdded event and run each character through your function. As another thing, you don't need to redefine your function for each player! It's better to put the function outside as you can still use it for each player.

1 comment

0

thank you so much!

local selectedTransparency

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		delay(.5, function()
			--// Function delay to make sure the character has been added.
			if chr then
				for _,parts in pairs(chr:GetChildren()) do
					wait()
					if parts:IsA("BasePart") or parts:IsA("Part") or parts:IsA("MeshPart") or parts:IsA("GuiBase3d") or parts:IsA("Decal") then
						selectedTransparency = 1
						parts.Transparency = selectedTransparency
						wait()
					else
					if parts:IsA("Accessory") then --// Ghost Mode
						parts:Remove() --// Don't have to add this.
					end
					end
					for _,parts_2 in pairs(parts:GetChildren()) do
						if parts_2:IsA("Decal") then
							parts_2.Transparency = 1 --// Will remove the face
						end
					end
				end
			end
	    end)
	end)
end)

1 comment

0

Supports meshes.

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