Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer
-- 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)

4 comments

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

0

Sure, i've done it. Check the script i've added below 'Requested Script (Ignore)'

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?

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.