How do I change the sitting animation while still being seated

  1. What do you want to achieve? So basically I want it so when you enter a seat, with your normal sit animation, and after 10 seconds pass, your sitting animation inside your Animate script (the one that is inside the Character, not the script itself, the animations that are parented to it.) would change while you’re still sitting on the seat.

  2. What is the issue? The animation does in fact change, but it only works if I stop sitting and sit again.

  3. What solutions have you tried so far? I’ve pretty much tried looking all over the web trying to find any kind of solution that fits my needs. But I can’t seem to find anything.

The Local Script where I’m trying to achieve this.

--This Local Script is inside the StarterCharacterScripts
local change animation = game.ReplicatedStorage.ChangeAnimationEvents
local player = game:GetService("Players").LocalPlayer

changeanimation.Sit.OnClientEvent:Connect(function(id)
	
	player.Character.Animate.sit.SitAnim.AnimationId = "rbxassetid://"..id..""
	
	local Tracks = player.Character.Humanoid.Animator:GetPlayingAnimationTracks()

	for i, track in pairs(Tracks) do --One of my poor attempts to try and refresh the animation while still being seated
		print(track)
		track :Stop()
		track :Play()
	end

end)

Edit: I should probably give more context on how the whole function works. So I have it so that when you sit in the chair, it activates a ticking timer in a script inside the character. Once this timer reaches a certain amount of time, it will fire a bindableevent to change the player’s sit animation. And the local script above is the said localscript that is activated on the clientevent.

2 Likes

Changing the animation ID (in game) from the animate script doesnt work as far as I know.

But you can use property changed event to detect when the humanoid is sitting. Then play an animation which has a higher priority than the sitting animation

local Loadedanim
local Animation = script.Animation -- Animation of your choice

Character.Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
	if Character.Humanoid.Sit == true then
		Loadedanim = Character.Humanoid.Animator:LoadAnimation(Animation)
		Loadedanim:Play()
	else
		Loadedanim:Stop() -- jumped out of seat
		-- stop animation
	end
end)
1 Like

this script might work

seat = script.Parent
function added(child)
	if (child.className=="Weld") then
		human = child.part1.Parent:FindFirstChild("Humanoid")
		if human ~= nil then
			anim = human:LoadAnimation(seat.sitanim)
			anim:Play()
		end
	 end
end

function removed(child2)
	if anim ~= nil then
		anim:Stop()
		anim:Destroy()
		human.Parent.HumanoidRootPart.Velocity = Vector3.new(0,0,0)
	end
end

seat.ChildAdded:connect(added)
seat.ChildRemoved:connect(removed)

Screenshot_126
This is a regular script situated within the seat, with an animation instance also in the seat named ‘sitanim’.