I made a combat script, and after some updating, ive come across the bug that makes all your punches either be combo 1, or combo 3, even though it should go 1,2,3,4. im in need to find a fix or an alternative way to fix this issue and this is my script. i am willing to replace the attribute, even though id rather keep it
local function SetCombo(char)
local combo = char:GetAttribute("Combo")
if combo < maxCombo then
char:SetAttribute("Combo", combo + 1)
else
char:SetAttribute("Combo", 1)
end
end
local animationCache = {}
game.Players.PlayerRemoving:Connect(function(plr)
animationCache[plr] = nil
playerCooldowns[plr] = nil
CooldownModule.RemoveCooldowns(plr)
end)
-- Function to cache an animation for a player
local function cacheAnimation(player, animationName, animationTrack)
-- Check if the player already has an entry in the cache
if not animationCache[player] then
animationCache[player] = {} -- If not, create a new table for the player
end
-- Store the animation track in the player's cache table with the given name
animationCache[player][animationName] = animationTrack
end
-- Function to retrieve a cached animation for a player
local function getCachedAnimation(player, animationName)
-- Check if the player has any cached animations
if animationCache[player] then
-- Retrieve the animation track with the given name from the player's cache table
return animationCache[player][animationName]
end
return nil -- Return nil if no animation found for the player with the given name
end
remote.OnServerEvent:Connect(function(plr, arg)
if not playerCooldowns[plr] or playerCooldowns[plr] <= time() then
playerCooldowns[plr] = time() + AbilityCooldown
local character = plr.Character
local cantM1 = character:GetAttribute("M1")
if cantM1 then return end
local selected = plr:FindFirstChild("Char")
if not selected then return end
local humanoid = character:FindFirstChildOfClass("Humanoid")
local attacking = character:GetAttribute("Attacking")
local combo = character:GetAttribute("Combo")
local sprinting = character:GetAttribute("Sprinting")
local stunned = character:GetAttribute("Stunned")
local blocking = character:GetAttribute("Blocking")
local dodging = character:GetAttribute("Dodging")
if attacking or stunned or blocking or dodging then return end
if character:GetAttribute("Sprinting") then return warn("sprinting") end
if character:FindFirstChild("iframe") then return end
if humanoid.Health <= 0 then return end
for i,v in pairs(plr.Character.Humanoid:GetPlayingAnimationTracks()) do
if v and v.Priority == Enum.AnimationPriority.Action then
v:Stop()
end
end
local animationfolder = game.ReplicatedFirst.Animations.Combat:GetChildren()
local anim
local folder
if selected.Value == "Fists" then
folder = punchAnims
elseif selected.Value == "Katana" then
folder = swordAnims
end
local track
if combo < maxCombo then
local cachedAnim = getCachedAnimation(plr, "Punch " .. tostring(combo))
if cachedAnim then
cachedAnim:Play()
character:SetAttribute("M1", true)
task.delay(AbilityCooldown, function()
if character then
ComboReset(character)
character:SetAttribute("M1", false)
end
end)
else
anim = folder[combo]
local animTrack = humanoid:LoadAnimation(anim)
animTrack:Play()
character:SetAttribute("M1", true)
task.delay(AbilityCooldown, function()
if character then
ComboReset(character, combo)
character:SetAttribute("M1", false)
end
end)
local name = "Punch " .. tostring(combo)
cacheAnimation(plr, name, animTrack)
end
soundremote:FireAllClients(punchWoosh[combo], character.HumanoidRootPart)
character:SetAttribute("Combo", combo+1)
tec.NormalHitbox(
character,
character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 4,
Vector3.new(5, 5, 5),
false,
.2,
3,
true,
false,
0,
false,
false
)
SetCombo(character)
else
soundremote:FireAllClients(punchWoosh[combo], character.HumanoidRootPart)
tec.NormalHitbox(
character,
character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * 4,
Vector3.new(5, 5, 5),
false,
.2,
3,
true,
true,
0,
false,
false
)
local cachedAnim = getCachedAnimation(plr, "Punch " .. tostring(combo))
if cachedAnim then
cachedAnim:Play()
character:SetAttribute("M1", true)
task.delay(.75, function()
if character then
character:SetAttribute("M1", false)
ComboReset(character)
end
end)
else
anim = folder[combo]
local animTrack = humanoid:LoadAnimation(anim)
animTrack:Play()
character:SetAttribute("M1", true)
task.delay(2, function()
if character then
character:SetAttribute("M1", false)
ComboReset(character)
end
end)
local name = "Punch " .. tostring(combo)
cacheAnimation(plr, name, animTrack)
end
SetCombo(character)
end
humanoid.WalkSpeed = 12
task.delay(.2, function()
if character and humanoid then
humanoid.WalkSpeed = 19
end
end)
end
end)
the code above is a snippet from my script with everything that needs to be seen, focus only on the part where it checks if combo > max combo and forward. Note: there are no errors in the script, and it is simply a bug i cannot fix, but my best guess is the way im setting the attribute, and using the task.delay.
