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

Im not sure why this sitting animation to a seat wont work?

Asked by 4 years ago

Im trying to make it so that when a player sits in a seat, a animation is applied to them.

local seat = script.Parent

function SeatIsSatIn(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local character = hit.Parent
        local humanoid = character.Humanoid
        wait(0.5) 

        if humanoid:GetState() == Enum.HumanoidStateType.Seated then 

            local animation = Instance.new("Animation")
            animation.AnimationId = "http://www.roblox.com/asset/?id=182435998" 

            local  track = humanoid:LoadAnimation(animation)
            track:Play()

            local function StateChanged(oldState, newState)
                if newState ~= Enum.HumanoidStateType.Seated then
                    track:Stop()
                end
            end

            humanoid.StateChanged:connect(StateChanged)
        end
    end
end

seat.Touched:connect(SeatIsSatIn)

I made this script a year ago when I was 8, it may not work, and it didnt..... Whats wrong with it. The script error finder on roblox didnt help me.

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
4 years ago

In Animations theres a thing called priorities. They are used to bypass or not bypass current animations. Use code below, We are going to be using action priority because its the recommended one for animations!

local seat = script.Parent

function SeatIsSatIn(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local character = hit.Parent
        local humanoid = character.Humanoid
        wait(0.5) 

        if humanoid:GetState() == Enum.HumanoidStateType.Seated then 

            local animation = Instance.new("Animation")
            animation.AnimationId = "http://www.roblox.com/asset/?id=182435998" 
            animation.Priority = Enum.AnimationPriority.Action

            local  track = humanoid:LoadAnimation(animation)
            track:Play()

            local function StateChanged(oldState, newState)
                if newState ~= Enum.HumanoidStateType.Seated then
                    track:Stop()
                end
            end

            humanoid.StateChanged:connect(StateChanged)
        end
    end
end

seat.Touched:connect(SeatIsSatIn)
0
It worked great, i had to alter it a bit though. fireyfoxninja21 9 — 4y
Ad

Answer this question