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

RigType not working as expected?

Asked by
Wayyllon 170
3 years ago
Edited 3 years ago

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

Log in to vote
0
Answered by
Wayyllon 170
3 years ago

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)

Ad

Answer this question