New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

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

Asked by 13 days 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 13 days 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 — 13d
Ad

Answer this question