Humanoid.RigType not working?

( Disclaimer: The Script Is Inside Of A Tool )

if script.Parent.Parent:FindFirstChild('Humanoid').RigType == Enum.HumanoidRigType.R6 then
	return
end

The error message says >Players.funnyfunns.Backpack.Pistol.AnimateR15:4: attempt to index nil with 'RigType'

2 Likes
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character

if Character:WaitForChild("Humanoid").RigType == Enum.HumanoidRigType.R6 then
    return
end

I’m using a server script, not a local script.

Try separating the check for the Humanoid and its RigType to ensure that the Humanoid can be found before trying to index the property:

local Tool = script.Parent
local Character = Tool.Parent

local Humanoid = Character:FindFirstChildOfClass("Humanoid")

if Humanoid then
   local RigType = Humanoid.RigType
end

What? Still nothing… it keeps printing the error.

FULL SCRIPT

local shoot = script:FindFirstChild('Shoot')
local debounce = false


local Tool = script.Parent
local Character = Tool.Parent

local Humanoid = Character:FindFirstChildOfClass("Humanoid")

if Humanoid then
	local RigType = Humanoid.RigType
end

script.Parent.Activated:Connect(function()
	if debounce == false then
		debounce = true
		
		local anim = Humanoid:LoadAnimation(shoot)
	
		anim:Play()
		
		wait(1.471)
		
		debounce = false
	end
end)

(I think I accidently flagged my post :open_mouth: )

Are you sure you are referencing the character properly?

When the tool is equipped, I am pretty sure you cant reference the character, so you will need to come up with a solution to storing the character before the player equips the tool

These are separate from one another, which means that even if the Humanoid does not exist, the function will still attempt to call :LoadAnimation() on the Humanoid. You need to include the check in the function and only call :LoadAnimation() if the condition was met:

script.Parent.Activated:Connect(function()
	if debounce == false then
		debounce = true
		
        local Humanoid = Character:FindFirstChildOfClass("Humanoid")

        if Humanoid then
	        local RigType = Humanoid.RigType
		    local anim = Humanoid:LoadAnimation(shoot)
            -- Continue
        end
    end
end

This is false – when the tool is equipped, it’s inside of the Character, which means that it could be referenced via script.Parent.Parent under the assumption that the script is directly inside of the Tool. Anything that is unequipped remains in the player’s Backpack.

local Tool = script.Parent
local isEquipped = false

Tool.Equipped:Connect(function()
    isEquipped = true
end)

Tool.Unequipped:Connect(function()
    isEquipped = false
end)

Tool.Activated:Connect(function()
   if isEquipped then
       doSomething()
   end
end)

Okay so I’ve found out how to do this. I think it works… well I tried it and it works.

local shoot = script:WaitForChild('Shoot')

script.Parent.Activated:Connect(function()
	local character = script.Parent.Parent
	
	local humanoid = character:FindFirstChild('Humanoid')
	local anim = humanoid:LoadAnimation(shoot)
	
	if humanoid.RigType == Enum.HumanoidRigType then
		return
	end
	
	anim:Play()
end)
1 Like

yeah, the reason you were indexing nil was because you were setting the Character to starterpack as soon as the player loaded in