Sleeping Animation not working?

-- Created by EndorsedModel --

---------- VARIABLES ----------

local seat = script.Parent
local sleepingR15 = seat.SleepingR15
local sleepingR6 = seat.SleepingR6
local sleepAnim

---------- CONNECTIONS ----------

seat.Changed:Connect(function(property) -- if a property in the seat changes
	
	if property ~= "Occupant" then return end -- if that property is not "occupant" then we'll ignore the change and stop the function
	
	local occupant = seat.Occupant
	
	if occupant then -- if we do have an occupant then do the stuff below
		local character = occupant.Parent
		local humanoid = character.Humanoid
		local player = game.Players:GetPlayerFromCharacter(character)
		if player and humanoid.RigType == Enum.HumanoidRigType.R15 then -- checks if we're using R15
			sleepAnim = humanoid:LoadAnimation(sleepingR15)
			sleepAnim:Play()
		elseif player then -- this is for if we're using R6
			sleepAnim = humanoid:LoadAnimation(sleepingR6)
			sleepAnim:Play()
		end
	elseif sleepAnim then -- if we don't have an occupant but the property changed that means someone just got up
		sleepAnim:Stop() -- stop the sleeping animation so the player who got up isn't stuck in a sleeping animation
	end
end)

The animation is running, as I checked with print statements-- yet the animation doesn’t show in-game! I have checked with the animation editor that the animation is right. Why won’t it work?
image

-- Created by EndorsedModel --

---------- VARIABLES ----------

local seat = script.Parent
local sleepingR15 = seat.SleepingR15
local sleepingR6 = seat.SleepingR6
local sleepAnim

---------- CONNECTIONS ----------

seat.Changed:Connect(function(property) -- if a property in the seat changes
	
	if property ~= "Occupant" then return end -- if that property is not "occupant" then we'll ignore the change and stop the function
	
	local occupant = seat.Occupant
	
	if occupant then -- if we do have an occupant then do the stuff below
		local character = occupant.Parent
		local humanoid = character.Humanoid
		local player = game.Players:GetPlayerFromCharacter(character)
		if player and humanoid.RigType == Enum.HumanoidRigType.R15 then -- checks if we're using R15
			sleepAnim = humanoid:LoadAnimation(sleepingR15)
			sleepAnim:Play()
		elseif player and humanoid.RigType == Enum.HumanoidRigType.R6 then -- this is for if we're using R6
			sleepAnim = humanoid:LoadAnimation(sleepingR6)
			sleepAnim:Play()
		end
	elseif sleepAnim then -- if we don't have an occupant but the property changed that means someone just got up
		sleepAnim:Stop() -- stop the sleeping animation so the player who got up isn't stuck in a sleeping animation
	end
end)

maybe this will work, i only added ‘and humanoid.RigType == Enum.HumanoidRigType.R6’ to the elseif statement

You animated it on an r6 rig, it can’t be used with a r15 rig

You want to make sure no animation is currently running when sitting on the seat.

There are two animations, one for r15 and r6

1 Like

No it sadly doesn’t work, I am testing on an R15 avatar btw.

---------- VARIABLES ----------

local seat = script.Parent
local sleepingR15 = seat.SleepingR15
local sleepingR6 = seat.SleepingR6
local sleepAnim

---------- CONNECTIONS ----------

seat.Changed:Connect(function(property) -- if a property in the seat changes

	if property ~= "Occupant" then return end -- if that property is not "occupant" then we'll ignore the change and stop the function

	local occupant = seat.Occupant

	if occupant then -- if we do have an occupant then do the stuff below
		local character = occupant.Parent
		local humanoid = character.Humanoid
		local player = game.Players:GetPlayerFromCharacter(character)
		local animator = humanoid:FindFirstChildOfClass("Animator")
		for i,v in ipairs(animator:GetPlayingAnimationTracks()) do
			v:Stop()
		end
		if player and humanoid.RigType == Enum.HumanoidRigType.R15 then -- checks if we're using R15
			sleepAnim = humanoid:LoadAnimation(sleepingR15)
			sleepAnim:Play()
		elseif player and humanoid.RigType == Enum.HumanoidRigType.R6 then -- this is for if we're using R6
			sleepAnim = humanoid:LoadAnimation(sleepingR6)
			sleepAnim:Play()
		end
	elseif sleepAnim then -- if we don't have an occupant but the property changed that means someone just got up
		sleepAnim:Stop() -- stop the sleeping animation so the player who got up isn't stuck in a sleeping animation
	end
end)```

I did that and it still doesn't work