So I’m helping develop a battlegrounds game yes. As I’m not that of an experienced scripter, I’ve come across some issues with input tracking. I’m trying to make a system where on the last attack of the sequence (an M1), you are airborne, you perform a downslam. Similarly, if you were holding jump before the last attack sequence, you perform an uppercut. However, if you meet none of these requirements, then the normal attack will play.
For more context, different characters have different special moves and requirements to meet them, however, most of them relate to input and state changes.
Furthermore, I’ve been brainstorming ways to make this compatible with NPC’S and mobile players. Thank you in advance ![]()
Here is my pre-existing code:
--// Services //
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
--// Folders //
local RepMods = ReplicatedStorage.Modules
local Manage = RepMods.Management
local RepUtils = RepMods.Utilities
local CoreRUtils = RepUtils.Core
local CombatMods = RepMods.Combat
local VelocityMods = RepMods.Velocity
--// Modules //
local Chrono = require(Manage:WaitForChild("Chrono"))
local AnimationManager = require(Manage:WaitForChild("AnimationManager"))
local StateManager = require(Manage:WaitForChild("StateManager"))
local ComboManager = require(Manage:WaitForChild("ComboManager"))
local CooldownManager = require(Manage:WaitForChild("CooldownManager"))
local ValueManager = require(Manage:WaitForChild("ValueManager"))
local CombatUtility = require(CoreRUtils:WaitForChild("CombatUtility"))
local HitboxClass = require(CombatMods:WaitForChild("HitboxClass"))
local HealthModule = require(CombatMods:WaitForChild("HealthModule"))
local RagdollModule = require(VelocityMods:WaitForChild("RagdollModule"))
local VelocityModule = require(VelocityMods:WaitForChild("VelocityModule"))
--// Configs //
local highlightTween = TweenInfo.new(0.5, Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local CombatModule = {}
function CombatModule.CheckAttackCompatability(character: Model)
local isCoreState = StateManager.CheckCoreStates(character, "currentState")
if isCoreState then return false end
local isOnCooldown = CooldownManager.IsOnCooldown(character, "attack")
if isOnCooldown then return false end
return true
end
function CombatModule.M1(character: Model, characterName: string?)
local isAttackCompatable = CombatModule.CheckAttackCompatability(character)
if not isAttackCompatable then return end
local characterName = CombatUtility.GetGuarenteedCharacterName(character, characterName)
StateManager.SetState(character, "currentState", "attack")
local combo = ComboManager.GetCombo(character, "M1") + 1
local isFinisher = CombatUtility.IsComboFinisher(characterName, combo)
local M1Data = CombatUtility.GetM1Data(characterName, combo)
local attackSet = CombatUtility.GetCharacterAttackSet(characterName)
local M1Id = attackSet[combo]
local charHrp: BasePart = character:FindFirstChild("HumanoidRootPart")
local plr = Players:GetPlayerFromCharacter(character)
local successReached = false
local M1Track = AnimationManager.LoadAnimation(character, "M1", M1Id, false, {
{"Hit", function()
ComboManager.Set(character, "M1", M1Data.TimeBeforeReset, 1)
successReached = true
local newHitbox = HitboxClass.new({
SizeOrPart = M1Data.Size,
Debris = 0.3,
InitialPosition = Chrono.ChronoServer.GetLatestCFrame(plr) * CFrame.new(0, -2.8, -3),
SpatialOption = "InBox",
Blacklist = {character},
ID = `M1_{character.Name}`,
VelocityPrediction = true,
UseLatencyCompensation = true,
Debug = false,
LookingFor = "Humanoid"
})
newHitbox.HitSomeone:Connect(function(hitCharacters: {Model})
HealthModule.Change((-M1Data.Damage * M1Data.DamageMultiplier), hitCharacters)
CombatModule.Stun(hitCharacters, 0.5)
CombatModule.ApplyHitEffect(hitCharacters)
if not isFinisher then
CombatModule.ApplyHitAnimation(hitCharacters, combo)
else
local lookVector = charHrp.CFrame.LookVector
local flatVector = Vector3.new(lookVector.X, 0, lookVector.Z)
RagdollModule.Start(hitCharacters, 2)
VelocityModule.Apply(hitCharacters, Vector3.one * M1Data.FinalKnockback, 0.3, flatVector)
end
end)
newHitbox:Start()
end}
}, M1Data.AnimationSpeedModifier)
AnimationManager.waitUntilFinished(M1Track)
StateManager.SetState(character, "currentState", nil)
if isFinisher then
CooldownManager.SetCooldown(character, "attack", M1Data.FinalCooldown)
ComboManager.Restart(character, "M1")
else
CooldownManager.SetCooldown(character, "attack", M1Data.CooldownSpeed)
end
end
function CombatModule.Stun(hitCharacters: {Model}, stunTime: number)
for index, hitChar in ipairs(hitCharacters) do
local currentState = StateManager.GetState(hitChar, "currentState")
if currentState == "stun" then continue end
StateManager.SetState(hitChar, "currentState", "stun")
local hitHum: Humanoid = hitChar:FindFirstChildOfClass("Humanoid")
ValueManager.SetValue(hitChar, "stunData", {
WalkSpeed = hitHum.WalkSpeed,
JumpPower = hitHum.JumpPower
})
hitHum.WalkSpeed = 0
hitHum.JumpPower = 0
end
task.delay(stunTime, function()
for index, hitChar in ipairs(hitCharacters) do
StateManager.SetState(hitChar, "currentState", nil)
local hitHum: Humanoid = hitChar:FindFirstChildOfClass("Humanoid")
local stunData = ValueManager.GetValue(hitChar, "stunData")
hitHum.WalkSpeed = stunData.WalkSpeed
hitHum.JumpPower = stunData.JumpPower
end
end)
end
function CombatModule.ApplyHitEffect(hitCharacters: {Model})
for index, hitChar in ipairs(hitCharacters) do
local newHighlight = Instance.new("Highlight")
newHighlight.OutlineTransparency = 1
newHighlight.Adornee = hitChar
newHighlight.FillColor = Color3.fromRGB(255, 0, 0)
newHighlight.DepthMode = Enum.HighlightDepthMode.Occluded
newHighlight.Parent = hitChar
local highlightTween = TweenService:Create(newHighlight, highlightTween, {
FillTransparency = 1
})
highlightTween:Play()
task.spawn(function()
highlightTween.Completed:Connect(function()
newHighlight:Destroy()
newHighlight = nil
highlightTween:Destroy()
highlightTween = nil
end)
end)
end
end
function CombatModule.ApplyHitAnimation(hitCharacters: {Model}, combo: number)
local hitAnims = CombatUtility.GetM1HitAnimations()
local hitId = hitAnims[combo]
for index, hitChar in ipairs(hitCharacters) do
AnimationManager.LoadAnimation(hitChar, "Hit", hitId)
end
end
return CombatModule
Please, feel free to give architectural feedback and support or a better code design.