tryna make a seat in where u sit on it and it plays a certain sitting animation. like on the game vibe train. but the script aint working. take a look pls
01 | local Seat = script.Parent |
02 | local Animation = script:WaitForChild( "Animation" ) |
03 | Seat.Changed:connect( function () --You can get the individual property changed event, but this is simpler. |
04 | if Seat.Occupant ~ = nil then |
05 | local Track = Seat.Occupant.Humanoid:LoadAnimation(Animation) --Load the animation |
06 | Track:Play() --Play the animation |
07 | Seat.Occupant.Humanoid.Jumped:wait() --Wait for player to leave the seat |
08 | Track:Stop() --Stop the animation |
09 | end |
10 | end ) |
pls help
Make sure you have your animation id ready
01 | local sitAnims = { 0 , 0 } --Paste the same one in twice, unless you want random ones |
02 |
03 | local seat = script.Parent --Link this to the seat |
04 | local playingAnim |
05 |
06 | local newAnim = Instance.new( 'Animation' ) |
07 | newAnim.AnimationId = 'rbxassetid://' ..sitAnims [ math.random(#sitAnims) ] |
08 |
09 | seat.Changed:Connect( function (property) |
10 | if property = = 'Occupant' then |
11 | local occupant = seat.Occupant |
12 | if not occupant then if playingAnim then playingAnim:Stop() return end end |
13 | playingAnim = occupant:LoadAnimation(newAnim) |
14 | playingAnim:Play() |
15 | end |
16 | end ) |
If this works make sure to accept it, if you have any questions I'll try to be active enough to help!