How would I make a skill system that calls upon a specific module for a move?

So, currently I want to make the attempt once I press on a certain tool, it’ll fire the toolname to the serverscript, and that server script will call upon a certain module script, but this is where I get stumped.

currently I have the local script like this

local Toolie = script.Parent

Toolie.Activated:Connect(function()
	
	if Debounce == true then return end
	
	if Debounce == false then
		Debounce = true 
		
		RS.CombatEvents.SkillSystem:FireServer(script.Parent.Name)
		
		task.wait(9)
		
		Debounce = false
		
	end
	
	
	
end)

Then within my actual skill server, I have a MainModule which is meant to be doing this,

function MainModule:CheckMove(Tool, ToolName, FuncName)
	if ToolName == Tool then
		print("lol.")
		return ToolName, true
	end
end

so then after that, I want to see if the Tool name is true to the ToolName/The Skill name, and fire that specific module within the server script, but it isn’t working in my favor, and I don’t know to set a module to a specific name like this

["SpinKick"] = function(par, par, par)
  --Skillandvariousotherscriptsplacedinhere
end

So instead I had to specific just fire out that module script, but that’s not really the way I wanted it to work.


	if Tool == "SpinKick" then
		DMG = 15
	end
	
	local Character = Player.Character
	local Hum = Character.Humanoid
	local animtracks = Player.Character.Humanoid:GetPlayingAnimationTracks()
	
	local Action, Length = SkM.getAnimation(Player.Character.Humanoid, 3)
	for _,v in pairs(animtracks) do
		v:Stop()
	end
	Action:Play()
	
	Action:GetMarkerReachedSignal("SpinKickHitbox"):Connect(function()
		print("Smooth sailing")
		local ToolName, EqualToolName = MM:CheckMove(Tool, Tool, FuncName) 
		print("Alr so what happened")
		if EqualToolName == true then
			print("YUHH")
			if ToolName == Tool then
				MM:AddSound(Player.Character.HumanoidRootPart, "BrutalHit", 1, false)
				print(ToolName, Tool)
				SkM.SpinKick(Player, Player.Character, DMG, Tool)
				print("Uhm?")
			end
		end
	end)
1 Like

you can make a table of module scripts/functions, you seem to almost have it

local modules = {
    ["SpinKick"] = require(mymodulescript) -- as module,
    ["SpinKick"] = require(mymodulescript).spinkick, -- as function in module
    ["SpinKick"] = function(parameters, ...) end, -- as function
}

do
    local toolModule = modules[ToolName]
    assert(toolModule)
    toolModule(player, etc)
end

Might I ask what is assert, and how the Second and Third spinkick work?

Or if the tool name is the module script then

local skill = require(pathToSkillModuleScriptParent:FindFirstChild(skillName))

assert errors if the first parameter is nil or false, it is very useful for debugging and keeping your code safe.

The second spinkick gets the function from the module script just like you would call the function module.spinkick(player, etc) when you don’t put the parenthesis lua grabs the function without using it and stores it in your table/variable.

The third spinkick is similar in that functions can be defined as variables

local myfunction = function(player)
    print("hello player:", player.Name)
end
-- identical
local function myfunction(player)
     print("hello player:", player.Name)
end

Functions as variable are functions like any other, lua even lets you shadow functions to overwrite them

local print = function()
    assert(false, "All prints are errors now!")
end

So, like this, I could make the modules like this

local FuncName = {
	["Punch"] = function(Player, Character, DMG, ToolName)


	end
	,
	["Kick"] = function(Player, Character, DMG, ToolName)

	end,
	["SpinKick"] = function(Player, Character, DMG, ToolName)

		local HitResult, EnemyChar = HBM.Detection(Player.Character, ToolName, Vector3.new(2.2, 2.2, 2), workspace, 0.4, 0.3)

		local Packet = {
			qitype = "YinnYang",
			attacktype = "Blunt",
			damage = DMG,
			blockable = true,
			blockbreak = true,
			ragdoll = true,
			knockback = true,
			KBTime =  0.4,
			ragdolltime = 2,
		}

		if HitResult == true then
			DM.DamageChecks(Character, EnemyChar, EnemyChar:FindFirstChild("Humanoid"), Packet)		
		end

	end,
	["Elbow"] = function(Player, Character, DMG, ToolName)

	end,
	["Grab"] = function(Player, Character, DMG, ToolName)

	end,
}

And they would work with your method, or would there be changes that are required to be made?

That will work! Going forward keep in mind that the parameters do need to stay the same since you will be calling all of the functions with the same parameters like FuncName[Kick](player, char, 30, "foot")

Ah, alright. Thank you so much for the assistance this was confusing me for a day or two.

Actually, there is one more thing. There is a warning due to the reason of the [“SpinKick”] is defined twice, is it something to ignore? @gertkeno

SpinKick is probably defined twice, I could point at it with code but I think roblox will give you a line number. Definitely do not ignore

Yeah, it is being defined twice,

SkillRemote.OnServerEvent:Connect(function(Player, Tool)
	
	if Tool == "SpinKick" then
		DMG = 15
	elseif Tool == "Kick" then
		
	elseif Tool == "Punch" then
		
	elseif Tool == "Grab" then
		
	elseif Tool == "Elbow" then
		
	end
	
	local ToolName, EqualToolName = MM:CheckMove(Tool, Tool, FuncName) 
	
	if EqualToolName == true then
		print("YUHH")
		if ToolName == Tool then
	
	
	local modules = {
		["SpinKick"] = require(script.SkillData).FuncName.SpinKick, -- as function in module
		["SpinKick"] = function(Player, Character, DMG, ToolName) end, -- as function
	}
	
	do
		local toolModule = modules[ToolName]
		assert(toolModule)
			toolModule(Player, Player.Character, DMG, Tool)
		end
	end
end

As it stands it’s giving me an error at the Second SpinKick.

I think if you remove one of them your error will be fixed, I think he just was showing you options on how to store it, choose the one you like better, and keep that one.


SkillRemote.OnServerEvent:Connect(function(Player, Tool)
	
	if Tool == "SpinKick" then
		DMG = 15
	elseif Tool == "Kick" then
		
	elseif Tool == "Punch" then
		
	elseif Tool == "Grab" then
		
	elseif Tool == "Elbow" then
		
	end
	
	local ToolName, EqualToolName = MM:CheckMove(Tool, Tool, FuncName) 
	
	if EqualToolName == true then
		print("YUHH")
		if ToolName == Tool then
	
	
	local modules = {
		["SpinKick"] = function(Player, Character, DMG, ToolName) end, -- as function
	}
	
	do
		local toolModule = modules[ToolName]
		assert(toolModule)
			toolModule(Player, Player.Character, DMG, Tool)
		end
	end
end

2 Likes