Sitting and getting up causes animation to never stop playing

Hello, it’s been a while since I’ve used this site lol, wanted to ask for some help on this, I seem to have an issue where the player if its doing my sitting animation and sits on a seat and then gets up it will never stop playing the sitting animation.

normal animation:

https://streamable.com/5hj1yg

“broken” animation:

https://streamable.com/635r5q

And here’s all the code I got on it…, #1 checks if the player is sitting, if it is then it disables script #2 which its the one that makes the player sit ( it would cause this current issue ) , else if the player isn’t sitting it just does nothing and waits until it is.

https://imgur.com/a/tJJv05C

any clue how I could fix this issue ?, maybe removing all the current playing animations after the player gets up? , I really don’t know…, all help is appreciated!

( replies might take a second since I’m currently slightly busy. )

The issue here is that setting script.Disabled to False from True is the equivalent from re-starting the script entirely. The result of this is that when you disable the script that handles the UI button, the animation that was playing inside of the character does not stop, and when you then re-enable the script, a new AnimationTrack is created as :LoadAnimation is used.

The best solution to this in your scenario is to simply combine the two scripts, and then use a bit of logic to determine when the animation should be playing and when button inputs should be responded to.
ex:
player is in seat, clicks button → ignore button input
player is not in seat, is not playing seat animation, clicks button → make the player start sitting
player is exiting a seat, is playing seat animation → stop the animation from playing

2 Likes

This sounds like it makes sense…, I will definitely try this and come back with a response shortly after I shower and eat, thank you a lot!!

thank you a lot for the idea of making the code work inside of the same script, it helped!!! here’s the current code that fixed 2 problems I had! :smiley:

local player = game.Players.LocalPlayer
local character = player.Character
repeat task.wait(0)
	character = player.Character
until character
local hum = character:WaitForChild("Humanoid")
local emote = hum:LoadAnimation(script.Parent.Emote)
playing = false

local function Clicking()

	if playing == false and hum.Sit == false then

		emote:Play()
		hum.WalkSpeed = 0
		hum.JumpPower = 0
		playing = true

	elseif playing == true and hum.Sit == false then

		emote:Stop()
		hum.WalkSpeed = 18
		hum.JumpPower = 31
		playing = false

	end

end

local function Sitting()

	if hum.Sit == true then
		print('sitting')
		emote:Stop()
		hum.WalkSpeed = 18
		hum.JumpPower = 31
		playing = false
	end

	if hum.Sit == false then
		print('not sitting')
	end
end

if script.Parent.MouseButton1Click:Connect(Clicking) then
	hum:GetPropertyChangedSignal("Sit"):Connect(Sitting)
end

and here’s a video on it working !

https://streamable.com/ed82r4

the issues I had were:
the player doing the sitting animation even tho a sitting animation was currently playing and the player not stopping the sitting animation, both have been fixed!, might fix other issues tomorrow, like being able to sit while dancing ( not supposed to happen ), etc but for now this was good work.