Why wont this sitting animation script work?

Im making a script for all the chairs inside to play animations when you sit in them but it wont work there all in a folder and it wont work.
Heres the script

repeat wait() until game:IsLoaded()
local chairs = workspace.Map.Insidebuilding.Chairs
local seatAnim = script:WaitForChild("SitAnimation1")

for _, v in pairs(chairs:GetChildren()) do
v.Chair.chair.seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local hum = v.Chair.chair.Occupant
	if hum then
		local LoadedAnim = hum:LoadAnimation(seatAnim)
		local Connection
		
		LoadedAnim:Play()
		
		Connection = hum:GetPropertyChangedSignal("Sit"):Connect(function()
			if hum.Sit == false then
				LoadedAnim:Stop()
			end
		end)
	end
	end)
end

There are no errors and the animation is made by my group for the group game.

This is probably do to the fact that you are using a roblox seat. When you sit on them they weld the character to the seat (making it so it prevents the animation).

1 Like

If its looped then it wont work.

1 Like

It worked before when i used it on a singular seat though then i tried doing a for loop for all the chairs and it broke.

How would i make it work for all chairs without putting a script in each one?

Can you put a print on the top of the Occupant changedSignal function and see if it prints.

1 Like

I put it before the for loop and it didnt print weird

local seatAnim = script:WaitForChild(“SitAnimation1”) does this resolve?

1 Like

What do you mean? Isnt that already in the script

Do you ever get an infinite yield possible message? and if not does it ever get past the game:IsLoaded() function

1 Like

Nope no infinite yield (30aaa)

You say it doesn’t make it to the loop. How far does the script make it?

1 Like

This is probably off-topic, but you should remove

repeat wait() until game:IsLoaded()

As the script is loaded with the game, so it’s unnecessary. (unless if it’s a local script.)

2 Likes

If i remove that it gives me this error: 21:00:59.067 Chair is not a valid member of Model “Workspace.Map.Insidebuilding.Chairs.Chair” - Server - SitAnimation1:7
Also @keith_220 i removed the repeat wait() until game:IsLoaded() like @Pat_WasTaken and it printed but it errored

1 Like

Workspace.Map.Insidebuilding.Chairs:WaitForChild(“Chair”) add a wait for child. EDIT: also make sure that the Chair instance is a child of Chairs
ANOTHER EDIT: v.Chair.chair.seat:GetPropertyChangedSignal(“Occupant”):Connect(function()
local hum = v.Chair.chair.Occupant
I also realized there is two different seat references. first you do v.Chair.chair.seat then you do v.Chair.chair.Occupant. you are refering to two different objects here

2 Likes

Now i get a infinite yield Infinite yield possible on 'Workspace.Map.Insidebuilding.Chairs.Chair:WaitForChild(“Chair”)

Workspace.Map.Insidebuilding.Chairs:WaitForChild(“Chair”) not Workspace.Map.Insidebuilding.Chairs.Chair:WaitForChild(“Chair”) EDIT: also refer to my edit in my other reply

1 Like

Where am i suspose to be putting this at? I cant put it at the chairs varible because its a for loop and it will get the children of the chair itself also i dont really understand what you said in the other reply

What is in the chairs folder? local chairs = workspace.Map.Insidebuilding.Chairs

1 Like

Workspace pictureYes1