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

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

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

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)

2 comments

0

Character.HumanoidRootPart or Character.Torso, 10/10 line.

0

True. The HumanoidRootPart can still be seen.

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