I need help with a animated seat script

I’m trying to make a seat that when a player seats in it, it plays a animation, but when i try the script, it just uses the default sit animation
Here’s the script:

seat = script.Parent
function added(child)
	if (child.className=="Weld") then
		local 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)

Here’s the explorer:
image

What can i do?

1 Like

I believe you have to set the animation priority to Action, in order to override the default animation; If I’m not wrong, you could do so like this:

Animation = Humanoid:LoadAnimation(seat.sitanim)
Animation.Priority = Enum.AnimationPriority.Action
Animation:Play()
1 Like

Didn’t work, maybe i did something wrong? (i’m new to lua, that’s why i believe that)

I did something similar to this, try this out

local seat = script.Parent
local animId = "rbxassetid://"..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)

Use the Occupant property to determine if someone is sitting on the seat, and then if someone is sitting, change their sittign animation id to the one you have and store them int a variable, and once they get off, use the varaible to change their sitting animation back to normal and then set the variable to nil

3 Likes

Same thing, didn’t work, but no errors in the output, however the animation does not appear

Wait hang on,

local animId = "rbxassetid://"..seat.sitanim.AnimationId

Should be

local animId = seat.sitanim.AnimationId

I think the rbxassetid:// is included as well, but just to be safe, before doing that change, print what’s insied animId. Also does the animation belong to you?

2 Likes

It worked, thank you so much! ^^

1 Like

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

1 Like