Currently I have a little ability bar where you can equip abilities. I want to know the best way of whenever you click one of the keys, the ability with that key is used. If I wanted to switch the ball in slot 1 to the rocket launcher in slot 3, now if I use slot 1 then the rocket launcher instead will be activated. I want to know the best way this is possible. Currently I’m using bindable functions, but there might be another way.
Each folder contains a bindable function, and I want it so whenever you drag the ability folder inside, it automatically works and it replaces the image in the slot to whatever the ability’s is. Any help would be appreciated
A little difficult to know depending on your setup, though most of the possible solutions would involve some sort of the following:
Your ability hotbar has no hard coupling with the direct abilities; instead, each ability in the hotbar would have a loadAbility function, which would be called however you’d like; it seems like you want some sort of drag functionality, but that’s beyond the scope of the explanation. Either way, this loadAbility would take in parameters; could either be a table/object containing the values, or separate strings with the name/image/etc, but either way this function would “load” your ability. You would also have an executeAbility function that would take this loaded ability and call it in some way. This could either be done by passing in the function directly that you want the ability to do, or you can link it somehow during the loadAbility function, or call a bindable with parameters from the loadAbility. The basic point is that you make this ability bar completely generic and the functionality would be loaded up externally. This would be effectively accomplished using modules scripts/object oriented programming.
Yes that was what I was thinking. Could I just possible make a bindable function for each ability slot and bind it to the ability function whenever it is equipped in that slot? Is there any cons to using bindable functions? Also how do I unbind bindable functions/events. Thanks for the reply.
I’ve recently did I system like this in my own game, what I’ve found works best is to have a value or an id for each ability and then whenever you equip the ability you change the value to the id of the ability. Then you can use .Changed which fires whenever the value is edited. Then have a dictionary/table of all the icons and images and set them to those images when you equip the ability. Then when it comes to using it you could call every time to find a RemoteEvent with the same name as the value/id then fire that.
Just have multiple dictionaries. This probably isn’t the most efficient way to do it but It’s what I did. You could have the animations rbxassetids in a dictionary as strings and then just recieve the animation
No, I this is what I used but I’m sure that there could be a possible be a way. You could store all of your dictionaries in a module script then require what you need.
I thought about a way. Do you think this is viable? :
When pressing a key to activate that equipped ability, it fires a remote event that handles all abilities. It takes the id/name of ability in as a parameter and in the server the remote fires a bindable event named as the id to another script that handles that certain ability. After successfully firing it fires back to the client to now update the gui to have a cooldown bar and also to play the player’s animation. Is this a secure way and would it have issues with players with high ping?
Yeah, that sounds like it should work. The only problem is if you have shop where you can buy other powers as then you would need to check if the player owns it through the server as exploiters can fire the RemoteEvent through the client.
Also I have a question. When playing an animation that is animated with a tool welded with a motor6d before the tool is welded to the player, will it still animate the tool while it gets welded during the animation? (For example I play animation on client then I weld part/tool to player on server)
Never mind that question, I came up with another idea framework. Is it possible I store functions with ids of the abilities in a module then inside those functions they call remote events to a module that stores the server functions. So just 2 modules one for client and server client fires remote to server and server gets functions inside server module? Maybe this would be better. No actually the client fires a remote function to return the cooldown so the client can update the cooldown bar. Is this exploitable or limiting? Also can it be scaled do you think?