What is best practice for handling a debounce for when a player is done emoting?

I have a loop where I am going through all the players and making them emote one at a time… I fire an event to the client which plays the emote.

I am thinking about maybe having a completed event on the client that will fire to the server letting the server know the player is done and then having a repeat wait until that debounce gets set… then it would go to the next player and so on.

[UPDATE: scratch this because it’s game breaking if someone decided to exploit] → so i think it will have to be a method that is server based.

does anyone have any suggestions for this?

Here’s some sudo:

for every player in the game
   activate emote (fire client)
   repeat 
     wait
   until emote completed
-- loop continues to the next player

note: maybe there is a humanoid event i can get on the server that will let me know when the animation is finished (currently researching)

4 Likes

You could do it on the server (would be easier) and use a .Stopped event on the animation. But if you want to start the animation on the client, maybe using a queue with a remote event. So basically you create a queue and push all the players into it, and every time the event is fired to the server (player finishes emote) it checks the queue head and if the player is the same whos next in the queue it pops the head and then sends the dance emote to the next player until the queue size is 0 (no more players to emote)

Also make sure to add a timeout that automatically makes the next players in queue start dancing just incase the current emoting player leaves the game or something and cant send the completed signal to the server

1 Like

so for this i’d have the player be moved back to another position once finished emoting. i didn’t put that bit in description. i thought animations were meant to be played on client though… would it work just fine if played on server?

1 Like

Yeah animations work on the server too. But don’t forget to add the timeout

2 Likes

oh why a timeout? these animations may be set to a specific time already. so cut down to say 1.5 seconds.

1 Like

If you’re using a .Completed connection I’m not sure it will fire if the player leaves the game while they are dancing

1 Like

if a player leaves could i not put conditions for that and then disconnect the stopped event while also forcing the loop to the next player?

1 Like

yeah ig but that’s cringe and more work than just adding a task.delay(animationLength) function and then task.cancel() on it once the .Completed thing runs

may be more work but better code quality overall right? task.delay(animation length) doesn’t seem like the best practice to me. seems kind of jank. i’d prefer to get rid of any possible race conditions so more work is fine if it does that. going with the conditions i cna also customize the user experience more if a player does end up leaving mid game. vs task.delay which may create awkwardness

Sure, but you’d also have to check if the player dies too btw and a couple other conditions that could prevent the animation from completing so timeout is easier imo

yeah i’m not too worried about what’s easiest because this is production code. i’m more concerned with customizing the user experience and making it as smooth/ high quality as possible

1 Like

idk how hardcoding checks for every condition the player could stop dancing is better than using a timeout

maybe something like this.

for every player in game
-move to dance position
-play dance emote
-set player dancing to player name
–if player leaves game then
—set player dancing to nil (which would continue to next player automatically instead of waiting the emote time, which would be jank. could also add customized ui saying a player left and can turn off whatever ui was supposed to be on during the player dancing)

if they leave the game or if they die or any other conditions where they could stop dancing

i wonder if you could use GetPlayingAnimationTracks(): on server and connect the .completed event through that value then still be able to play the animation on client. just a thought though while reading api

right
dsfsdfgsdfgsdfgsdfgsdfgsdfgsdf

The m6d positions replicate but the actual animator loaded tracks dont so the server can’t use GetPlayingAnimationTracks()

oh gotchu. clutch. didn’t get that far in

what would the task.cancel be for in this method?

To cancel the delay (the timeout) from running if it’s not needed

1 Like