Now this is probably going to be a very niche and specific post, but I have a combat system and Im tyring to make two types of attacks using mousebutton1 and mousebutton2. Mousebutton1 works fine but once i press mousebutton2, it turns sets a character attribute named “canSwing” to false and whenever its false, the player cannot do M1/M2 inputs nor walk or jump. The heavy attack portion, for some reason, just sets it to false and doesnt re-enable it. The animation has the keyframes required as well I seriously dont know whats going on (no errors pop up in the output)
“Light Attack”
if Args.Event == "LightAttack" then
if not Character:GetAttribute("canSwing") then return end
local Combo = Character:GetAttribute("Combo")
if Combo == 1 then
Character:SetAttribute("canSwing", false)
Player:SetAttribute("canSwing", false)
Character:SetAttribute("Combo", Character:GetAttribute("Combo") + 1)
Character:SetAttribute("LastSwing", DateTime.now().UnixTimestampMillis)
local Swing = Humanoid:LoadAnimation(WeaponSettings.Swing1)
Swing:Play()
Swing.KeyframeReached:Connect(function(Keyframe)
if Keyframe == "Hit" then
CombatManager.CreateHitbox(Player, Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3), WeaponSettings.HitboxSize)
end
if Keyframe == "End" then
task.delay(WeaponSettings.SwingCD, function()
Character:SetAttribute("canSwing", true)
Player:SetAttribute("canSwing", true)
end)
end
end)
elseif Combo == 2 then
Character:SetAttribute("canSwing", false)
Player:SetAttribute("canSwing", false)
Character:SetAttribute("Combo", Character:GetAttribute("Combo") + 1)
Character:SetAttribute("LastSwing", DateTime.now().UnixTimestampMillis)
local Swing = Humanoid:LoadAnimation(WeaponSettings.Swing2)
Swing:Play()
end)
elseif Combo == 3 then
Character:SetAttribute("canSwing", false)
Player:SetAttribute("canSwing", false)
Character:SetAttribute("Combo", 1)
Character:SetAttribute("LastSwing", DateTime.now().UnixTimestampMillis)
local Swing = Humanoid:LoadAnimation(WeaponSettings.Swing3)
Swing:Play()
Swing.KeyframeReached:Connect(function(Keyframe)
if Keyframe == "Hit" then
CombatManager.CreateHitbox(Player, Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3), WeaponSettings.HitboxSize)
end
if Keyframe == "End" then
task.delay(WeaponSettings.SwingCD, function()
Character:SetAttribute("canSwing", true)
Player:SetAttribute("canSwing", true)
end)
end
end)
end
end
“Heavy Attack”
if Args.Event == "HeavyAttack" then
if not Character:GetAttribute("canSwing") then return end
local Combo = Character:GetAttribute("Combo")
if Combo == 1 then
Character:SetAttribute("canSwing", false)
Player:SetAttribute("canSwing", false)
Character:SetAttribute("Combo", Character:GetAttribute("Combo") + 1)
Character:SetAttribute("LastSwing", DateTime.now().UnixTimestampMillis)
local Swing = Humanoid:LoadAnimation(WeaponSettings.HeavySwing)
Swing:Play()
Swing.KeyframeReached:Connect(function(Keyframe)
if Keyframe == "Hit" then
CombatManager.CreateHitbox(Player, Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3), WeaponSettings.HitboxSize)
end
if Keyframe == "End" then
task.delay(WeaponSettings.HeavyCD, function()
Character:SetAttribute("canSwing", true)
Player:SetAttribute("canSwing", true)
end)
end
end)
elseif Combo == 2 then
Character:SetAttribute("canSwing", false)
Player:SetAttribute("canSwing", false)
Character:SetAttribute("Combo", Character:GetAttribute("Combo") + 1)
Character:SetAttribute("LastSwing", DateTime.now().UnixTimestampMillis)
local Swing = Humanoid:LoadAnimation(WeaponSettings.HeavySwing)
Swing:Play()
Swing.KeyframeReached:Connect(function(Keyframe)
if Keyframe == "Hit" then
CombatManager.CreateHitbox(Player, Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3), WeaponSettings.HitboxSize)
end
if Keyframe == "End" then
task.delay(WeaponSettings.HeavyCD, function()
Character:SetAttribute("canSwing", true)
Player:SetAttribute("canSwing", true)
end)
end
end)
elseif Combo == 3 then
Character:SetAttribute("canSwing", false)
Player:SetAttribute("canSwing", false)
Character:SetAttribute("Combo", 1)
Character:SetAttribute("LastSwing", DateTime.now().UnixTimestampMillis)
local Swing = Humanoid:LoadAnimation(WeaponSettings.HeavySwing)
Swing:Play()
Swing.KeyframeReached:Connect(function(Keyframe)
if Keyframe == "Hit" then
CombatManager.CreateHitbox(Player, Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -3), WeaponSettings.HitboxSize)
end
if Keyframe == "End" then
task.delay(WeaponSettings.HeavyCD, function()
Character:SetAttribute("canSwing", true)
Player:SetAttribute("canSwing", true)
end)
end
end)
end
end
If you need me to post the other scripts that comply with the code then let me know.