How to play custom R15 sitting animation on player while sitting

I have a seat I’m using that a user can interact with to sit on by pressing ‘E’. However when the player sits I want to use my own animation. My approach to this was replacing the animation ID for sitting in the players’ ‘Animate’ script. This unfortunately only works when the Animation settings are set to player choice. Is there a way to use my own sitting animation but with Animation settings in the game set to Standard?

4 Likes

There’s 2 main ways of doing it, discussed here. You can get the animation script and replace parts of that code to your ids, or replace the animation found in the animation script. I provided an example there, for the later, but don’t think it will work in your case. I don’t have a custom sit animation, but you can try this code in a server script and should work. You’ll need to replace the animation id with your own.

local NewAnimID = 123456789 --PASTE NEW ANIMATION ID HERE

local function ReplaceAnimation(character, name, animId)
	local Animator = character.Animate
	local Animation = Instance.new("Animation")
	Animation.AnimationId = "http://www.roblox.com/asset/?id="..animId
	
	local ToolNone = Animator:FindFirstChild(name)
	if ToolNone then
		local NewAnim = Instance.new("StringValue")
		NewAnim.Name = name
		Animation.Name = name.."Anim"
		Animation.Parent = NewAnim
		ToolNone:Destroy()
		NewAnim.Parent = Animator
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		ReplaceAnimation(character, "sit", NewAnimID)
	end)
end)
7 Likes

Doesn’t this just replace the animation…?

My bad, I’ve been answering different variants of this question recently and didn’t read it close enough. In that case you need to change the animation table inside the script, line 50 that looks like…

sit = 	{
				{ id = "http://www.roblox.com/asset/?id=507768133", weight = 10 } 
			},	

to your own id

If you’re using a custom fork of the Animate script, you can either expunge any references to the Seated pose or only remove Line 702. It should look like this:

Humanoid.Seated:connect(onSeated)

If you aren’t using a custom Animate script fork, then you will have to manually clear the animation off and run your own animation elsewhere. There are functions available to you to get playing AnimationTracks and many ways to check if a player has taken a seat - you’ll want to visit the Humanoid page on the Developer Hub to see them. The animation that runs when a player sits is “SitAnim”. You can stop this animation when a player sits down and then run your own animation.

1 Like

How would I replace the default Animate script with my own including the edit?

1 Like

Grab a copy from Play Solo. Run an F5 or F6 server in Studio, look under your Character and “Animate” will be there. Copy this script, terminate the Play Solo session and then paste it in StarterCharacterScripts. This won’t be overwritten and the default script won’t get added.

3 Likes