Object Oriented Abilities, how?

What I’ve considered is making the input in the components themselves, but I don’t think it’s the right approach, I want everything to be exploiter free, or at least the important stuff like Power that determines the push distance.

Well, I was forced to make some modules client and server compatible. To do this, I would have to use RunService to detect if the script is on the client or server.

Then, you would have to implement this into the initpush function. I would look for an event and connect it to the initpush function.

So, I tried sending the whole module, which did not work, because you cannot send the whole module to the client while doing so, as functions do not send through remotes (probably for security reasons) so you will have to have the module on both the client and server.

I’m sure that this is possible but I’m not too experienced in OOP so I can’t really help with coding it, but I can always make suggestions and ideas.

And I agree with that.

Could you please give me an example of this, doesn’t need to be OOP just a sample, so I can have an understanding, thank you.

So, RunService has many different functions you can use to find out what you’re running.

RunService:IsClient() will return a Boolean determining if the current script is executing from a client.

RunService:IsServer() will return the opposite value.

There’s also RunService:IsStudio()

But implementing these functions in completely object-oriented code will be easy to impossible depending on what you want to do with them.

But I do not really understand how a client required script can be also a server, I don’t understand the way of making it on the server too.

And even if its possible, how would i link everything up?

I know for sure that there’s no rule saying you cannot require a module from the client and server, because I have done that about 3 times before I assume.

I think it is possible, but you would have to add many or and and statements to filter out the OOP with the IsClient boolean value you got, and what to fire. However, this is very hard to do without the help of loadstring, but I would not recommend using that. You can require another module that is specific to the server/client from the module you are currently using, which has the functions you desire for that specific platform. Then, you can add a “Default” module consisting of functions that run on the client and server.

I personally would do it with a main Abilities module that creates a “controller” object for a player on the server, then maybe functions for loading and unloading certain abilities, and each ability has it own object with an Activate function.

idk really how to explain it better tho.

1 Like

Can you give some code example?

But I kinda understand what you mean, but wouldn’t this require me to link everything to a superclass so i could access the values?

1 Like

Sounds kinda like ECS, not exactly OOP but that debate is for software engineers and architects.

As long as it’s componentalized so that you can modularize it and drag and drop it wherever server or client or even shared between, that’s what matters for code organization.

But yeah this is how I organize my code now:

1 Like

The issue summary is basically how would i go about making a client have an ability “equipped” so input results will be relative to that, thats my actual question.

For this just have one input handler system on the client.

And a way to store dictionary to key to event

{[Enum.KeyCode.W] = "Default" }

Or the other way around

{Default = {W, A, S, D}}

Manipulate this dictionary data based on your equip system.

Detect using UIS or CAS fire event.

In the server loop through the Server components or shared components that belong to default.

Another dictionary

{"Default" = {PushComponent, Damage component, HitboxComponent} }

Then do stuff based on the components given that you want for only the server to do like knockback or damage, clients will only get visual effects components or UI components.

ECS system is there to help detect the components and automatically execute code based on that. (Separate the Data from the actual functions.)

Imagine this:
default is a module script in replicated storage
the player owns the default module (bought it)
he equips it (if he clicks, he will push with it, with the respective power of the hand that he was equipped) - How would i do this?

@dthecoolest @SubtotalAnt8185 @PostVivic

Well, you can have some scripts in the equipped tool that will require the default module and look for custom settings in other modules.

Im starting to believe that making the inputs in the components is actually a good idea, requiring the main module on the client as a matter of it being “equipped” the components will just start listening for input, to optimise this I would use parallel lua

what do you think? @SubtotalAnt8185

That is a good idea, but it might be hard to code. You can look for a tool in the character and look up some info about it from storage.

default module / functionality:

local PushComp = require(script.Push)
local default = {}
default.__index = default

function default.new(Power)
	local PushNew = PushComp.new(Power)
	local DefHand = {}
	DefHand.PushStartListen = PushNew["StartListen"]
	DefHand.PushFunc = PushNew["Push"]
	setmetatable(DefHand, default)
	return DefHand

function default:EnableAllListeners(Key1)

return default

push component:

local pushcom = {}
pushcom.__index = pushcom

function pushcom.new(power)
	local self = setmetatable({}, pushcom)
	self.Power = power
	return self

function pushcom:Push()

local uis = game:GetService("UserInputService")
function pushcom:StartListen(Key)
	uis.InputBegan:Connect(function(input, gp)
		if gp then return end
		if (input.UserInputType or input.KeyCode) == Enum.UserInputType[Key or "MouseButton1"] then

return pushcom

This worked well, i guess I will stick with this and make remote events instead of just printing e

(dont mind that i didnt make an or statement for the keycode too)