Sound:Play() only works sometimes

Hello there. I am trying to make a drum sequencer in roblox. Unfortunately, sometimes the :Play() function just flat out doesn’t work. Also it is a bit off beat but I don’t think that’s fixable because of roblox’s stupid wait function. Below is my code and a video of the problem.

local tempo = 130
local waitTime = 60 / tempo / 4

local color1 = Color3.fromRGB(163, 161, 165)
local setcolor1  = Color3.fromRGB(255, 139, 139)

local color2 = Color3.fromRGB(119, 119, 121)
local setcolor2  = Color3.fromRGB(206, 112, 112)

local line1 = game.Workspace.DrumSequencer.Line1:GetChildren()
local line2 = game.Workspace.DrumSequencer.Line2:GetChildren()
local line3 = game.Workspace.DrumSequencer.Line3:GetChildren()
local line4 = game.Workspace.DrumSequencer.Line4:GetChildren()

game.Workspace.Play.ClickDetector.MouseClick:Connect(function()
	while true do
		for i = 1, #line1 do
			local part = line1[i]
			if part.Color == setcolor1 then
				game.Workspace.Sounds["808Kick"]:Stop()
				game.Workspace.Sounds["808Kick"]:Play()
			elseif part.Color == setcolor2 then
				game.Workspace.Sounds["808Kick"]:Stop()
				game.Workspace.Sounds["808Kick"]:Play()
			elseif part.Color == color1 then
				
			elseif part.Color == color2 then
			
			end
			wait(waitTime)
		end
	end
end)

game.Workspace.Play.ClickDetector.MouseClick:Connect(function()
	while true do
		for i = 1, #line2 do
			local part = line2[i]
			if part.Color == setcolor1 then
				game.Workspace.Sounds["808Clap"]:Stop()
				game.Workspace.Sounds["808Clap"]:Play()
			elseif part.Color == setcolor2 then
				game.Workspace.Sounds["808Clap"]:Stop()
				game.Workspace.Sounds["808Clap"]:Play()
			elseif part.Color == color1 then

			elseif part.Color == color2 then

			end
			wait(waitTime)
		end
	end
end)

game.Workspace.Play.ClickDetector.MouseClick:Connect(function()
	while true do
		for i = 1, #line3 do
			local part = line3[i]
			if part.Color == setcolor1 then
				game.Workspace.Sounds["808Snare"]:Stop()
				game.Workspace.Sounds["808Snare"]:Play()
			elseif part.Color == setcolor2 then
				game.Workspace.Sounds["808Snare"]:Stop()
				game.Workspace.Sounds["808Snare"]:Play()
			elseif part.Color == color1 then

			elseif part.Color == color2 then

			end
			wait(waitTime)
		end
	end
end)

game.Workspace.Play.ClickDetector.MouseClick:Connect(function()
	while true do
		for i = 1, #line4 do
			local part = line4[i]
			if part.Color == setcolor1 then
				game.Workspace.Sounds["808HiHat"]:Stop()
				game.Workspace.Sounds["808HiHat"]:Play()
			elseif part.Color == setcolor2 then
				game.Workspace.Sounds["808HiHat"]:Stop()
				game.Workspace.Sounds["808HiHat"]:Play()
			elseif part.Color == color1 then

			elseif part.Color == color2 then

			end
			wait(waitTime)
		end
	end
end)

A while loop will yield the code I believe so maybe wrap it in a coroutine and also if you want it to be better synced make it a local script