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
3: Call SetCombo each click
setCombo(char)
4: If your animation for punching stops, reset the combo with this function:
(inside of click detection)
animation.Stopped:Connect(function() --Disables after a second of animation being stopped
ComboReset(char, combo)
end)
(outside of click detection)
local function ComboReset(character, oldcombo)
task.delay(1, function()
local currentCombo = character:GetAttribute("Combo")
if oldcombo == 5 then return end
if currentCombo - 1 == oldcombo and not character:GetAttribute("Attacking") then
character:SetAttribute("Combo", 1)
end
end)
end
Try this and see if this setup helps. Incorporate your punching detection and logic alongside it.
Also consider having your click detection inside of a local script, place the code above this post inside of a server script and connect it with a remote event.
i dont usually like taking other people scripts, but im trying to understand yours so i can improve. “combo” attribute keeps showing up as nil. where did i mess up?
local remote = script.Parent["M1 event"]
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:SetAttribute("Combo", 1)
character:SetAttribute("GuardHealth", 4)
print(character:GetAttribute("Combo"))
end)
end)
local function setCombo(char)
local combo = char:GetAttribute("Combo")
if combo < 5 then
char:SetAttribute("Combo", combo+1)
else
char:SetAttribute("Combo", 1)
end
end
local function ComboReset(character, oldcombo)
task.delay(1, function()
local currentCombo = character:GetAttribute("Combo")
if oldcombo == 5 then return end
if currentCombo - 1 == oldcombo and not character:GetAttribute("Attacking") then
character:SetAttribute("Combo", 1)
end
end)
end
remote.OnServerEvent:Connect(function(char)
ComboReset(char)
print(char:GetAttribute("Combo", 1))
end)