Sleeping Animation

So I wanted to make a Sleeping Animation and when you sit on a sit part it makes you do the Animation.

Its working in Studio but on in the actual game. I tried to change the Animation but that still didn’t work.

Can we see your script? If you have any?

2 Likes

Yes I have this one

---------- 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)

Is it in a server script? And do you get any errors when you test in an actual game?

I tried to use Server Script and Local Script, They both dont work anymore. I didnt get any errors.

Oh. Is the animation priority set to action or something else? If it is set to action I’m not sure what is going wrong sorry :sleepy:

I tired all of the animation priorities, non of them work. :disappointed_relieved: Thanks for the help tho!

Sorry, I hope you can fix it :cry:

This may sound stupid but did you publish the game and made sure it’s in the correct version?

What about placing a part on the seat instead of using “onSeat” script? The script will work when the player is touching the part located on the script.

So, when roblox “sits” the character down, it is actually playing an animation under the “animate” local script in the character:


And so, if you change the animation Id to whatever animation you want to play (You can do this by changing it with a script, and other ways I guess) then it will play that animation instead.
For the animation, set it to action if you want it to override tool animations, but if you want the character to be able to hold a tool while sitting, consider changing it to movement.

Where is this script stored @macawMark

Inside of the Sit Part. The animation is in the script. Yes and I did make sure it’s the same version.

Try this:


seat = script.Parent
function added(child)
if (child.className==“Weld”) then
player = child.part1.Parent:FindFirstChild(“Humanoid”)
if player.RigType == Enum.HumanoidRigType.R15 then – checks if we’re using R15
anim = player: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)


Obviously you’ll need to space it out, I’m unsure how to paste scripts correctly here.

So I tried now on a different game and now it works in game and in studio. Weird.

So now Im trying it in a Group Game and its not working. Maybe it has something to due with the type of game?