Support for making a follow-up attack for a fork of the default Roblox sword

What I’m hoping to achieve what the title says, a second attack after the first M1 attack is done, however I can’t seem to get it to work.

I can’t seem to get this to work. Refer to local function heartbeat() for my problem.

I attempted to ask a fellow developer, but they were unable to get it from a small code snippet I provided and they redirected me here. Any help would be appreciated.

wait()

local tool = script.Parent
local config = require(tool:WaitForChild('Config'))

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()

while character.Parent == nil do
	character.AncestryChanged:Wait()
end

local humanoid = character:WaitForChild("Humanoid")
local root = character:WaitForChild("HumanoidRootPart")
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera

local function createAnimation(id)
	local animObject = Instance.new("Animation")
	animObject.AnimationId = 'rbxassetid://'..id
	local animator = humanoid:FindFirstChildOfClass("Animator") or humanoid
	return animator:LoadAnimation(animObject)
end

local RNG = Random.new()

local function createSound(id, volume, playbackspeed)
	local sound = Instance.new("Sound")
	sound.Parent = tool:FindFirstChild("Handle") or tool
	sound.SoundId = 'rbxassetid://'..id
	sound.RollOffMaxDistance = 300
	sound.RollOffMinDistance = 10
	sound.Volume = volume
	sound.RollOffMode = Enum.RollOffMode.Linear
	sound.PlaybackSpeed = playbackspeed

	return sound
end

local runService = game:GetService("RunService")
local tags = game:GetService("CollectionService")
local userInputService = game:GetService("UserInputService")
local contextActionService = game:GetService("ContextActionService")

local TAU = math.pi * 2

local idleAnimation = createAnimation("18667011797")
local equipAnimation = createAnimation("18667481925")
local transitionAnimation = createAnimation("18681939146")
local newIdleAnimation = createAnimation("18681887817")

local attackAnimation1 = createAnimation("18683773748")
local attackAnimation2 = createAnimation("18683953036")
-- 18683953036

--local equipSound = createSound("")
local swooshSound = createSound("5835032207", 0.5, 1)
local swooshSoundAlt = createSound("5835032207", 0.5, 1.2)
local impactEquipSound = createSound("8595977193", 0.5, 1)

local gui = nil
local toolEquipped = false

local isAttacking = false

local mouseDown = false

local lastAttack = 1

local replicatedStorage = game:GetService("ReplicatedStorage")
local cameraShaker = require(game.ReplicatedStorage.CameraShaker)
local camera = workspace.CurrentCamera
local camShake = cameraShaker.new(Enum.RenderPriority.Camera.Value, (function(shakeCFrame)
	camera.CFrame = camera.CFrame*shakeCFrame
end))	
camShake:Start()

local function performChecksForAttacking()
	if humanoid.Health <= 0 then
		return
	end
	
	return true
end

local function renderStepped(dt)
	if gui and not userInputService.TouchEnabled then
		if gui:FindFirstChild("Mouse") then
			gui.Mouse.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
		end
	end
end

local function activated()
	mouseDown = true
end

local function deactivated()
	mouseDown = false
end

local function attack()
	if performChecksForAttacking() == nil then return end
	isAttacking = true
	
	attackAnimation1:Play()
	wait(0.25)
	swooshSound:Play()
	wait(0.42 - 0.25)
	isAttacking = false
end

local function attackTwo()
	if performChecksForAttacking() == nil then return end
	isAttacking = true

	attackAnimation2:Play()
	wait(0.25)
	swooshSoundAlt:Play()
	wait(0.42 - 0.25)
	isAttacking = false
end

local function heartbeat()
	local Tick = runService.Stepped:wait()
	if mouseDown == true and isAttacking == false and (Tick - lastAttack < 1) then
		attackTwo()
	elseif mouseDown == true and isAttacking == false then
		attack()
	end
	lastAttack = Tick
end

local function equipped()
	_G.ForceShiftLock = true
	
	toolEquipped = true

	userInputService.MouseIconEnabled = false

	gui = script.GUI:Clone()
	gui.Parent = player:WaitForChild("PlayerGui")
	
	equipAnimation:Play(0)
	swooshSound:Play()
	task.wait(0.4)
	camShake:Shake(cameraShaker.Presets.SfothSwordTrigger)
	impactEquipSound:Play()
	wait(0.1)
	idleAnimation:Play(0)
	wait(0.25)
	equipAnimation:Stop()
	idleAnimation:Stop()
	transitionAnimation:Play(0)
	swooshSound:Play()
	wait(0.1)
	swooshSoundAlt:Play()
	wait(0.1)
	swooshSound:Play()
	wait(0.1)
	swooshSoundAlt:Play()
	wait(0.7)
	newIdleAnimation:Play(0)
end

local function unequipped()
	_G.ForceShiftLock = false
	
	userInputService.MouseIconEnabled = true
	
	mouseDown = false
	toolEquipped = false
	
	idleAnimation:Stop()
	newIdleAnimation:Stop()
	transitionAnimation:Stop()
	equipAnimation:Stop()
	
	if gui then
		gui:Destroy()
		gui = nil
	end
end

runService.RenderStepped:Connect(renderStepped)
runService.Heartbeat:Connect(heartbeat)

humanoid.Died:Connect(unequipped)
tool.Equipped:Connect(equipped)
tool.Unequipped:Connect(unequipped)

tool.Activated:Connect(activated)
tool.Deactivated:Connect(deactivated)

Cheers!

Hi! This problem is still plaguing my work on my project, was hoping if anyone knew what to do? Here’s a smaller code snippet of the problem.

local function attack()
	if performChecksForAttacking() == nil then return end
	isAttacking = true
	
	attackAnimation1:Play()
	wait(0.25)
	swooshSound:Play()
	wait(0.42 - 0.25)
	isAttacking = false
end

local function attackTwo()
	if performChecksForAttacking() == nil then return end
	isAttacking = true

	attackAnimation2:Play()
	wait(0.25)
	swooshSoundAlt:Play()
	wait(0.42 - 0.25)
	isAttacking = false
end

local function heartbeat()
	local Tick = runService.Stepped:wait()
	if mouseDown == true and isAttacking == false and (Tick - lastAttack < 1) then
		attackTwo()
	elseif mouseDown == true and isAttacking == false then
		attack()
	end
	lastAttack = Tick
end

Thanks, cheers.