Attempt to index nil with humanoid

I’m trying to make parts of a tool go transparent when the player dies using the Humanoid.Died script signal but whenever the game loads it gives me an error “Players.TheUserThatIsTheUser.Backpack.Knife.ViewmodelConfigurations:22: attempt to index nil with ‘Humanoid’”
Here is my code for this:

player.Character.Humanoid.Died:Connect(function()

rightarm.Transparency = 1

leftarm.Transparency = 1

end)

For context, player = game.Players.LocalPlayer and right and left arm are parts.
I have also tried making a while true do that will constantly check if the players Humanoid Health value is 0 with an if statement to no avail.

Sorry if this looks a bit sloppy it’s my first time making a topic.

Sometimes it takes time and needs to wait until it is found.

Try:

local Players =game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Char:WaitForChild("Humanoid")

And continue from there

1 Like

Use this script:

script.Parent:WaitForChild("Humanoid").Died:Connect(function()
	if script.Parent:WaitForChild("Humanoid").RigType == "R6" then
		script.Parent:FindFirstChild("Right Arm").Transparency = 1
		script.Parent:FindFirstChild("Left Arm").Transparency = 1
	else
		script.Parent:FindFirstChild("RightLowerArm").Transparency = 1
		script.Parent:FindFirstChild("RightUpperArm").Transparency = 1
		script.Parent:FindFirstChild("RightHand").Transparency = 1
		
		script.Parent:FindFirstChild("LeftLowerArm").Transparency = 1
		script.Parent:FindFirstChild("LeftUpperArm").Transparency = 1
		script.Parent:FindFirstChild("LeftHand").Transparency = 1
	end
end)

This script is an Script, not an LocalScript, and put it into StarterPlayer > StarterCharacterScripts
and done.