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

How can I make it so when someone sits in a seat, it applys an animation I made to them?

Asked by 8 years ago

How would I be able to make it so when someone sits in a seat in your game, it makes them do a sit animation, that I made, until they get out of the seat? I made a sit animation, but I just can't figure out how to apply it to a player when they are sitting.

2 answers

Log in to vote
0
Answered by
Unlimitus 120
8 years ago

The Humanoid Instance has an invisible property called HumanoidStateType, this tells you what the Humanoid is doing (Sitting, Running, Dead, Jumping, and more!) So you can write a function like this:

If your script is inside the seat:

local seat = script.Parent

function SeatIsSatIn(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        local character = hit.Parent
        local humanoid = character.Humanoid
        wait(0.5) -- Wait a little bit so that the character has time to sit.
        if humanoid:GetState() == Enum.HumanoidStateType.Seated then -- Make sure the humanoid is sitting
            local animation = Instance.new("Animation")
            animation.AnimationId = "http://www.roblox.com/asset/?id=182435998" -- Put your AnimationID here, currently Gangnam Style
            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
@Unlimitus, I made this account just to say thanks! I really needed that script. Zatrizon 0 — 5y
0
Strange. now its not working Zatrizon 0 — 5y
Ad
Log in to vote
0
Answered by 8 years ago

Whenever you sit on a seat it applies a weld when you touch it, you'd probably have to make your own custom seat.

Answer this question