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!