Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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
PlayerAdded is for when they join the game CharacterAdded is when the character spawns in tge game User#5423 17 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

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.

0
thank you so much! HalfPinky456 12 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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)
0
Supports meshes. namespace25 594 — 6y

Answer this question