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

RigType not working as expected?

I wrote some code so that when a player sits down, it will detect if they have an R6 or R15 avatar and adjust the animation that it puts on them depending on their rig type

R6Animation = script.Parent.R6Animation
R15Animation = script.Parent.R15Animation
Seat = script.Parent

Seat.ChildAdded:Connect(function(Child)
	if Child.ClassName ~= "Weld" then end
	if Child.Part1:FindFirstChild("HumanoidRootPart") ~= true then end
	local PlayerModel = Child.Part1.Parent
	local Animator = PlayerModel.Humanoid.Animator
	if PlayerModel.Humanoid.RigType == 0 then
		AnimationLoader = Animator:LoadAnimation(R6Animation)
		AnimationLoader:Play()
	else
		AnimationLoader = Animator:LoadAnimation(R15Animation)
		AnimationLoader:Play()
	end
end)
Seat.ChildRemoved:Connect(function(Child)
	if Child.ClassName ~= "Weld" then end
	if Child.Part1:FindFirstChild("HumanoidRootPart") ~= true then end
	local PlayerModel = Child.Part1.Parent
	local Animator = PlayerModel.Humanoid.Animator
	AnimationLoader:Stop()
end)

However, for some reason, when it gets to the "== 0" bit it wont play the r6 animation until i change the indicator to ~= 1, and then it wont play the r15 animation until i change it back. Any ideas on why?

Solved, leaving up for others who make the same mistake.

1 answer

Oops! It seems that HumanoidRigType is actually an Enum Value! Heres the fixed code:

R6Animation = script.Parent.R6Animation
R15Animation = script.Parent.R15Animation
Seat = script.Parent

Seat.ChildAdded:Connect(function(Child)
	if Child.ClassName ~= "Weld" then end
	if Child.Part1:FindFirstChild("HumanoidRootPart") ~= true then end
	local PlayerModel = Child.Part1.Parent
	local Animator = PlayerModel.Humanoid.Animator
	if PlayerModel.Humanoid.RigType == Enum.HumanoidRigType.R6 then
		AnimationLoader = Animator:LoadAnimation(R6Animation)
		AnimationLoader:Play()
	elseif PlayerModel.Humanoid.RigType == Enum.HumanoidRigType.R15 then
		AnimationLoader = Animator:LoadAnimation(R15Animation)
		AnimationLoader:Play()
	end
end)
Seat.ChildRemoved:Connect(function(Child)
	if Child.ClassName ~= "Weld" then end
	if Child.Part1:FindFirstChild("HumanoidRootPart") ~= true then end
	local PlayerModel = Child.Part1.Parent
	local Animator = PlayerModel.Humanoid.Animator
	AnimationLoader:Stop()
end)

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