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

How to make player play custom animation when sitting in seat?

Asked by
ka3r 14
4 years ago

How do I make it so that when the player sit in a seat it plays a custom animation rather than the default ROBLOX sitting animation?

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago
-- Server Script

local Players = game:GetService("Players") -- Our player service to use the PlayerAdded & CharacterAdded events.
local SitAnimID = 507776043 -- Set to your specified animation id to replace the default sit idle animation.

Players.PlayerAdded:Connect(function(Player) -- On player added
    Player.CharacterAdded:Connect(function(Character) -- When character is added
    local Animation = Character:FindFirstChild('SitAnim', true) -- Finding the sit animation in the character
    Animation.AnimationId = ('rbxassetid://%s'):format(SitAnimID) -- Replacing animation id with yours.
    end)
end)

Hope this has helped, please learn from this and have a good day. If you have anything else you want to add on you can ask me. :)

Requested Script (Ignore)

-- Server Script

local Players = game:GetService("Players") -- Our player service to use the PlayerAdded & CharacterAdded events.
local SitIdleAnim = 507776043 -- Set to your specified animation id to replace the default sit animation.

local Seats = {
[workspace.Seat1] = 507770818;
[workspace.Seat2] = 507770677;
}
-- For each seat as the key, the value will the animation you want to play

Players.PlayerAdded:Connect(function(Player) -- On player added
    Player.CharacterAdded:Connect(function(Character) -- When character is added
    local Animation = Character:FindFirstChild('SitAnim', true) -- Finding the sit animation in the character
    local Humanoid = Character.Humanoid -- So we can use the GetPropertyChangedSignal

    Humanoid:GetPropertyChangedSignal('SeatPart'):Connect(function()
     local AnimationValue = Seats[Humanoid.SeatPart] -- if the part exists in the table as a key
     if not AnimationValue then  -- if it's not then we'll set it to our idle animation
        Animation.AnimationId = ('rbxassetid://%s'):format(SitIdleAnim) 
       else -- else if the animation does exist then it'll set to it's value that's in the table
        Animation.AnimationId = ('rbxassetid://%s'):format(AnimationValue)
      end
    end)        
   end)
end)
0
Thanks! However, do you know how to make it play an animation when the player is only sitting on a specific seat? Like for example seat1 will be used as a bed, so I use your code to play the sleeping animation on it. However, I'll be using seat2 as a chair, but when I sit on it, it plays the bed animation for seat1. How do I make seat2 have it's own animation? I hope you can understand and help me ka3r 14 — 4y
0
Sure, i've done it. Check the script i've added below 'Requested Script (Ignore)' User#31525 30 — 4y
0
Hello, trying to have multiple copies of "Seat1". To make things easier I'll reference the original seat1 as "st1" and the cloned as "st1jr" The properties of both "st1" and "st1jr" are the same (I just used Ctrl+D), when sitting on "st1" the correct sitting animation plays. However, sitting on "st1jr" causes the "SitIdleAnim" to play. How do I make it so all s1 in the server plays the same ani? ka3r 14 — 4y
0
Sorry for the late comment. I've noticed that the script is having trouble finding "seat1" when it's inside a model. Instead of having to do "game.Workspace.Model.Model.Seat1" which will then have to be changed everytime the parent of Seat1 is changed, is there a way to find seat1 regardless of it's parent? Thanks in advance. ka3r 14 — 4y
Ad

Answer this question