Animation not working correctly

I am trying to make a seat that plays an animation when the player sits, but when the player sits their HumanoidRootPart is in the correct place and their actual character is offset-ed. How do I fix this?

This is what I want the animation to look like:

But when I try it:

I have a server-script as a child of the seat, here is the code:

local seat = script.Parent
local ani = 'rbxassetid://8207037192'

function childADDED(child)
	
	if (child.ClassName=="Weld") then
		local human = child.Part1.Parent:FindFirstChild("Humanoid")
		local animator = human:WaitForChild("Animator")
		print(human.Parent, child.Parent)
		if human ~= nil then
			local newAnim = Instance.new('Animation')
			newAnim.AnimationId = ani
			anim = animator:LoadAnimation(newAnim)
			anim:Play()
		end
		
	 end
end

function childREMOVED(child2)
	if anim ~= nil then
		anim:Stop()
		anim:Remove()
	end
end

seat.ChildAdded:connect(childADDED)
seat.ChildRemoved:connect(childREMOVED)

Thanks in advance for the help!

local seat = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://8207037192"
animation.Parent = script

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		local humanoid = seat.Occupant
		local animator = humanoid:WaitForChild("Animator")
		local loadAnim = animator:LoadAnimation(animation)
		repeat
			task.wait()
		until loadAnim.Length > 0
		loadAnim:Play()
	end
end)

It may be an issue related to the position of the animation itself (how the character is manipulated when the animation plays). I’ve gone with a much simpler approach to playing an animation upon a seat being occupied.

Is this a local script or server script by the way? I assume it is the latter.

I think it’s because the dummy’s position is changed when animating, judging by the grids on the floor.

I would tell the OP to make it so that it animates on the spot and not move the whole body to the chair, because if it does, then it’s going to show the “offset” behavior.

1 Like

He’s not parenting the animation instance, easy mistake to make, I just noticed myself and added a line to assign the “Parent” property a valid instance.

1 Like

I just tested your script and it runs exactly the same, it might actually be the animation and not the script, but I am still unsure of why it would do that. Am I animating it wrong, somehow?

Also I stated that it is a server-sided script as a child of the seat right above my code.

I just re-animated the Dummy where I didn’t move it from the original position and it worked. I didn’t realize that, that was what you were talking about. Thanks!

Now I have 30 animations to re-animate… :pensive:

1 Like