Is this an efficient setup?

I’m currently trying to create a magic attack system and got the base done. Before I start making the effects, I want to know if this is an efficient system. By efficient I mean memory costs, delay/speed, etc. Here is the first part.

game.Players.PlayerAdded:Connect(function(player)
	remotesFolder.Start.OnServerEvent:Connect(function(player, parameterInfo)
		local moveFunctions = require(game.ReplicatedStorage.Modules.Magic[parameterInfo["MagicType"]].MoveFunctions)
		moveFunctions["Move"..parameterInfo["MoveNumber"]](player, parameterInfo, "Start")
	end)
	remotesFolder.End.OnServerEvent:Connect(function(player, parameterInfo)
		local moveFunctions = require(game.ReplicatedStorage.Modules.Magic[parameterInfo["MagicType"]].MoveFunctions)
		moveFunctions["Move"..parameterInfo["MoveNumber"]](player, parameterInfo, "End")		
	end)	
end)

Basically what this does, is on .PlayerAdded I create a remote folder specifically for the player, and their remotes go in there. The start remote is the beginning of the attack, and the end remote is the release. All of their attack remotes will be received here. For example, If they have 5 moves all of it gets linked to these remotes.

Once the remote is fired, I have a module script with each attacks move effects which I call. It looks something like this.

local module = {
	Move1 = function(player, parameterInfo, moveOrder)
		if moveOrder == "Start" then

		end

		if moveOrder == "End" then
				
		end
	end,
}

This will create the magic effects. These parts are the most important so far, but I have a couple more questions.

I will be using Region3, .Touched, and maybe other methods for damaging players. I was thinking of having module script functions for each of these magic functions, such as "Can Attack’, “HitCheck”, “Start Cooldown”, so it’s all linked and easily changeable. Is this the best way?

If anyone could provide any tips on this system, that would be great. Thanks! :hear_no_evil:

1 Like

Hey Fusionet!

In terms of performance, that is perfectly fine! If you are requiring the same module script each time, you should define it as a local at the top rather than requiring it each time. Otherwise, looks great to me! I personally love remote security, so please secure your remotes with checks! Exploiters will take advantage and use attacks they are not supposed to or at times they aren’t supposed to!

1 Like

Thanks for the response! I would define it at the top, but there is over 20 magics. Is there any way I could work around this? Maybe looping through all the modules and assigning a variable to each one? And I definitely will secure this from exploiters. :hear_no_evil:

Hey Fusionet!

You can always keep the magics in a single ModuleScript. Do this by keeping them seperated.

local module = {
	magicattack = function(player,argument)
		
	end,
	fireattack = function(player,argument)
		
	end
	--so on and so on
}

return module

By doing this, you can have all your attacks inside one module. Calling the required ModuleScript.fireattack(player,“testvariable”) could condense it into 1 module script for all attacks.

You can change up the variables that are fired with each attack, I just put basic ones.

2 Likes

It’s a good idea but there is over 20 magics with 5 moves each. The module will get extremely long and hard to navigate so I don’t think I’ll do this but thanks! :hear_no_evil:

You should make a module for each magic