Hello there! I need to animate local models of towers locally (game’s genre is Tower Defense). I got these ways to animate,but I dont know whats the best:
one local script with remote event where global script sends data with tower,need to wait for the end of playing animation and id of anim
create one local script for every tower placed which detects the change of state in the value
create one local without any contact with global one
I tried with first way,but it works bad. I want to try second one,but I aware its unoptimized and made bad. Whats the best way to animate local models of these or you have another way to do it?
I could be wrong, but can’t you just use normal animations and animate in the server (under the condition that you use Roblox animations and that Roblox animations replicate smoothly)? If you are planning on animating via scripts, then you 100% must use local scripts to do so if you want a smooth transition. What method you choose is up to you, although I’d personally chose a local approach (say you want to Tween the model, the client would detect the change and animate on the client while the server would only change the respective values) independent of server events so that the server doesn’t have to stress over anything other than calculating when something hit something else (so to sum up, animating would take part in the client while the server would simply calculate, choosing whether you use one script and one event or a script for each tower is up to you).
If I am correct, local scripts won’t run if they are in the Workspace (only if under your character), so your only options are StarterGui, StarterCharacterScripts, and StarterPlayerScripts. I personally would put mine under StarterPlayerScripts as I’d want the script to keep running even after I reset. Now, like I said, you have to choose whether you use multiple or one. It really doesn’t matter for as long as it works (and of course, it doesn’t kill performance). Personally, I would probably use one script as an event handler, and from there use individual scripts for each character that would be linked with a BindableEvent. Something like this:
The server would handle the interactions (or it could be individual scripts within the tower, not sure), then it would fire the AnimationEvent (a RemoteEvent), which EventMainHandler would pick up and fire the TowerEvent (a BindableEvent) of the appropriate tower. Then, the [InsertTowerNameHere]Handler would pick up the signal and animate appropriately.
EDIT: After thinking about this, something like this would be redundant. I’d put RemoteEvents under each tower. AnimationEvent as well as EventMainHandler would be redundant. Each tower handler (e.x.: ScoutHandler) will listen to the events of each placed tower (which you can do by utilizing CollectionService and adding a listener to each tower), and when an event is fired, it will play the appropriate animation. This would look something like this:
Of course, it is up to you to decide how you want to do this. Another way would be to have a single remote event and a single script doing all the animating, whether that is already pre-written in the script or via ModuleScripts. All in all, you should be the one choosing which approach you want to follow as it isn’t something we can really decide on.