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

How do I make a players character torso turn transparent with the OnPlayerEntered function?

Asked by 5 years ago

function OnPlayerEntered(player)

humanoid = player.Parent:FindFirstChild("Humanoid")

if humanoid then

game.Players:GetPlayerFromCharacter(player)

player.Character.Torso.Transparency = 0.5

end

end

game.Players.PlayerAdded:Connect(OnPlayerEntered)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Line 2 is your error. The Parent of a Player object is the Workspace, so what you're really doing is finding a nil Humanoid in the Workspace, which causes FindFirstChild() to return nil. The Humanoid is always a child of the player's Character:

local humanoid = player.Character:FindFirstChild("Humanoid")

Additionally, if your game allows R15 rigs (R15 avatars), Torso will not work because there is an UpperTorso and a LowerTorso.

Assuming your game allows R15:

local function OnPlayerEntered(player)
    local humanoid = player.Character:FindFirstChild("Humanoid")
    if humanoid then
        player.Character.UpperTorso.Transparency = 0.5
        player.Character.LowerTorso.Transparency = 0.5
    end
end
game.Players.PlayerAdded:Connect(OnPlayerEntered)

Assuming your game allows R6 but not R15:

local function OnPlayerEntered(player)
    local humanoid = player.Character:FindFirstChild("Humanoid")
    if humanoid then
        player.Character.Torso.Transparency = 0.5
    end
end
game.Players.PlayerAdded:Connect(OnPlayerEntered)
0
Character.HumanoidRootPart or Character.Torso, 10/10 line. Ziffixture 6913 — 5y
0
True. The HumanoidRootPart can still be seen. DeceptiveCaster 3761 — 5y
Ad

Answer this question