So, I have M1 script for a battlegrounds game, and it works all good. I just need to make it so it resets the combo when you haven’t punched in awhile (e.g 2 seconds).
Here’s my script.
game.ReplicatedStorage.Events.M1.OnServerEvent:Connect(function(plr)
if plr.Character.Values.CanAttack.Value then
plr.Character.Values.CanAttack.Value = false
local playbackSpeeds = {2.5, 3, 2}
local pitch = math.random(1, #playbackSpeeds)
local chosenSpeed = playbackSpeeds[pitch]
plr.Character.Humanoid.JumpHeight = 0
plr.Character.HumanoidRootPart.M1.PlaybackSpeed = chosenSpeed
plr.Character.HumanoidRootPart.M1:Play()
local pressCount = plr.Character:FindFirstChild("PressCount")
if not pressCount then
pressCount = Instance.new("IntValue", plr.Character)
pressCount.Name = "PressCount"
pressCount.Value = 0
end
pressCount.Value = pressCount.Value + 1
local inAir = plr.Character.Humanoid.FloorMaterial == Enum.Material.Air
if pressCount.Value == 1 then
local anim1 = Instance.new("Animation", plr.Character.Humanoid)
anim1.AnimationId = 'rbxassetid://17343637684'
plr.Character.Humanoid:LoadAnimation(anim1):Play()
elseif pressCount.Value == 2 then
local anim2 = Instance.new("Animation", plr.Character.Humanoid)
anim2.AnimationId = 'rbxassetid://17343654418'
plr.Character.Humanoid:LoadAnimation(anim2):Play()
elseif pressCount.Value == 3 then
local anim3 = Instance.new("Animation", plr.Character.Humanoid)
anim3.AnimationId = 'rbxassetid://17335827602'
plr.Character.Humanoid:LoadAnimation(anim3):Play()
elseif pressCount.Value == 4 then
local anim4 = Instance.new("Animation", plr.Character.Humanoid)
if inAir then
anim4.Archivable = false
local anim5 = Instance.new("Animation", plr.Character.Humanoid)
anim5.AnimationId = 'rbxassetid://17335871504'
wait(0.1)
plr.Character.Humanoid:LoadAnimation(anim5):Play()
end
anim4.AnimationId = 'rbxassetid://17335806584' --17278893953
plr.Character.Humanoid:LoadAnimation(anim4):Play()
end
plr.Character.Values.Attacking.Value = true
-- local anim = Instance.new("Animation", plr.Character.Humanoid)
-- anim.AnimationId = 'rbxassetid://17270813124'
-- plr.Character.Humanoid:LoadAnimation(anim):Play()
if pressCount.Value == 4 then
plr.Character.Humanoid.WalkSpeed = 0
--wait(0.6)
else
plr.Character.Humanoid.JumpPower = 0
plr.Character.Humanoid.WalkSpeed = 5
--wait(0.6)
end
if pressCount.Value == 3 then
plr.Character.Humanoid.WalkSpeed = 5
plr.Character.Humanoid.JumpPower = 50
--wait(0.6)
end
local connection
connection = plr.Character.Hitbox.Touched:Connect(function(hit)
task.spawn(function()
if hit.Parent:FindFirstChild("Humanoid") and hit.Name == "HumanoidRootPart" then
hit.Parent.Humanoid.Died:Connect(function()
ragdoll.Start(hit.Parent)
end)
local force = Instance.new("BodyVelocity", hit.Parent.HumanoidRootPart)
force.P = 25
force.MaxForce = Vector3.new(1,1,1) * math.huge
local direction = (hit.Parent.HumanoidRootPart.CFrame.Position - plr.Character.HumanoidRootPart.CFrame.Position)
force.Velocity = (direction + Vector3.new(0,1,0)).Unit * 25
game.Debris:AddItem(force, 0.1)
local impact = script[pressCount.Value]:Clone()
impact.Parent = hit
impact:Destroy()
if pressCount.Value == 4 then
hit.Parent.HumanoidRootPart.CanTouch = false
ragdoll.Start(hit.Parent)
local force = Instance.new("BodyVelocity", hit.Parent.HumanoidRootPart)
force.P = 25
force.MaxForce = Vector3.new(2,2,2) * math.huge
local direction = (hit.Parent.HumanoidRootPart.CFrame.Position - plr.Character.HumanoidRootPart.CFrame.Position)
force.Velocity = (direction + Vector3.new(0,1,0)).Unit * 33
game.Debris:AddItem(force, 0.1)
else
local force = Instance.new("BodyVelocity", hit.Parent.HumanoidRootPart)
force.P = 25
force.MaxForce = Vector3.new(1,1,1) * math.huge
local direction = (hit.Parent.HumanoidRootPart.CFrame.Position - plr.Character.HumanoidRootPart.CFrame.Position)
force.Velocity = direction.Unit * 10
game.Debris:AddItem(force, 0.1)
end
-- plr.Character.Hitbox.CanTouch = false
hit.Parent.HumanoidRootPart.CanTouch = false
hit.Parent.Humanoid:TakeDamage(4)
hit.Parent.Humanoid.WalkSpeed = 0
plr.TotalDamage.Value += 4
wait(0.3)
hit.Parent.HumanoidRootPart.CanTouch = true
wait(0.5)
hit.Parent.Humanoid.WalkSpeed = 22
-- plr.Character.Hitbox.CanTouch = true
if hit.Parent.Values.Ragdoll.Value and hit.Parent.Humanoid.Health > 0 then
wait(1.5)
-- hit.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
hit.Parent.Humanoid.PlatformStand = false
ragdoll.Stop(hit.Parent)
end
end
end)
end)
if pressCount.Value >= 4 then
wait(0.7)
else
wait(0.3)
end
plr.Character.Values.CanAttack.Value = true
-- plr.Character.Hitbox.CanTouch = false
if pressCount.Value >= 4 then
pressCount.Value = 0
end
plr.Character.Values.Attacking.Value = false
plr.Character.Humanoid.WalkSpeed = 22
plr.Character.Humanoid.JumpHeight = 7.2
connection:Disconnect()
end
end)