How do I check when the animation in this script ended?

Hello there, amazing people!

(Yep, it’s me back again with another dumb question which probably has like the easiest solution)

But anyways, I want to check when the animation full animation in this script ends. Basically it’s a module script which will play a full MoonAnimator animation. But I want to detect when it finishes the animation.

Extra info: It is called from a LocalScript.

Code

[Code removed so nobody can copy my code.]

Any help is appreciated!

Please read the full code before replying, the code isn’t like that. If that was it, I would’ve never made this post.

2 Likes

The first animation(camera one), ends when the event gets disconnected(Connection:Disconnect()). Therefore you can make some kind of custom event which fires right after:

Connection:Disconnect()
CameraAnimStopped:Fire() --where CameraAnimStopped is a BindableEvent

The other animations are actual AnimationTracks, therefore you can detect them directly using the .Stopped event:

LoadedAnimation:Play()
LoadedAnimation.Stopped:Connect(function()
	print(LoadedAnimation.Name.." stopped!, you can fire another bindable event for this")
end)
1 Like

Hm, good idea. But since it’s getting called from a LocalScript, should I fire a RemoteEvent to the server, then fire it back to the client? And at the end of the script I could do something like this?

return {
    ["CameraAnimationEnded"] = RemoteEvent.OnClientEvent;
};

Also, sorry for my awful amount of questions, I just don’t get things fast.

If you need two way communication consider using InvokeServer() instead via a RemoteFunction instance.

1 Like

[Code removed so nobody can copy my code.]

CameraAnimationEnded.OnClientInvoke

Lua believes you’re attempting to index the “OnClientInvoke” property for its value here. It needs to be an assignment expression.

CameraAnimationEnded.OnClientInvoke = function()
	print("Camera animation ended!");
	return true
end;

RemoteFunctions need to return something back to the invoker as well.

TYSM! I’ve been just trying to fix this problem for the past day, you saved a whole lot of my time!

Yeah, I removed the .OnClientInvoke part, and it worked just fine!