Help with animation script

Hello!

So i want to make a script that if you sit on a seat, an custom sitting animations plays.

But when i sit, no animation plays. Just the standard animation.

I’ve tried to get the animation in the script. But still nothing happens. No error in the output.

I will appreciate every help.

Also here’s the script:

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:Remove()
	end
end

seat.ChildAdded:connect(added)
seat.ChildRemoved:connect(removed)
local seat = script.Parent
local animId = seat.sitanim.AnimationId
local defaultAnim = "http://www.roblox.com/asset/?id=2506281703"
local formeroccupant

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = seat.Occupant
	if humanoid then
		local char = humanoid.Parent
		char.Animate.sit.SitAnim.AnimationId = animId
		formeroccupant = char
	else			
		formeroccupant.Animate.sit.SitAnim.AnimationId = defaultAnim
		formeroccupant = nil
	end
end)

Directly reference the sitting animation, I have given this script so many times for the same issue. Do not change the defaultAnim variable, only change the AnimationId in the sitanim animation. Although this will work if you’re in r15, in R6 you may need to tweak the defaultAnim variable to have the default animation for sitting for R6 users, or you could maybe try this?

local seat = script.Parent
local animId = seat.sitanim.AnimationId
local defaultAnim
local formeroccupant

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = seat.Occupant
	if humanoid then
		local char = humanoid.Parent
		local sit = char.Animate.sit.SitAnim
		if not defaultAnim then 
			defaultAnim = sit.AnimationId
		end
		sit.AnimationId = animId
		formeroccupant = char
	else			
		formeroccupant.Animate.sit.SitAnim.AnimationId = defaultAnim
		formeroccupant = nil
	end
end)

So first time anyone sits it stores the default animation for your game

2 Likes

Thanks for the help! And yes, i use R6.

1 Like

Alright, if the game is full R6, you may need to use the 2nd script to store the default animation of R6 as the default animation for the first script is for R15 last time I used it

If you have anymore issues don’t be afraid to make another post!

1 Like

I’ve did it :wink:
Thanks for the help anyway!

EDIT: You got a new follower!

1 Like