Help me with this apple script. The script should skip to the next song after ~30 seconds if the artist is "Latex Wednesday", if it's not then let it play in it's entirety. but for some reason after as non-Latex Wednesday song plays, it doesn't then skip after ~30s if the next track is a latex wednesday song?

tell application "Spotify"
	-- Check if Spotify is running
	if it is running then
		-- Save the current volume and then mute Spotify
		set currentvol to sound volume
		set sound volume to 0
		
		-- Enable shuffle and repeat modes
		set shuffling to true
		set repeating to true
		
		-- Start playing the specified playlist
		play track "spotify:playlist:6nE7wCfHb6lC2LDnjXw3vB"
		--play track "spotify:artist:4M8ylCkjsmaKPovYLrAHeO"
		
		-- Get the current day of the week and hour
		set currentTime to current date
		set currentDay to weekday of currentTime
		set currentHour to (hours of (currentTime - (time to GMT))) mod 24
		
		-- Initialize the track list and set loop counter
		set trackNameList to {}
		set trackCountList to {}
		
		-- Determine loopCounter and outputFile based on current hour
		if currentHour ≥ 6 and currentHour < 12 then
			-- 6AM logic
			set outputFile to "/Users/dominicwood/Scripts/SpotifyRepeat6AM.txt"
			if currentDay is Saturday or currentDay is Sunday then
				set loopCounter to random number from 50 to 80
			else
				set loopCounter to random number from 30 to 50
			end if
		else if currentHour ≥ 12 and currentHour < 18 then
			-- 12PM logic
			set outputFile to "/Users/dominicwood/Scripts/SpotifyRepeat12PM.txt"
			if currentDay is Saturday or currentDay is Sunday then
				set loopCounter to random number from 70 to 100
			else if currentDay is Wednesday or currentDay is Friday then
				set loopCounter to random number from 50 to 70
			else
				set loopCounter to random number from 40 to 60
			end if
		else if currentHour ≥ 18 and currentHour < 20 then
			-- 6PM logic
			set outputFile to "/Users/dominicwood/Scripts/SpotifyRepeat6PM.txt"
			if currentDay is Saturday or currentDay is Sunday then
				set loopCounter to random number from 80 to 110
			else if currentDay is Friday or currentDay is Wednesday then
				set loopCounter to random number from 60 to 90
			else
				set loopCounter to random number from 50 to 70
			end if
		else if currentHour ≥ 20 and currentHour < 22 then
			-- 8PM logic
			set outputFile to "/Users/dominicwood/Scripts/SpotifyRepeat8PM.txt"
			if currentDay is Saturday or currentDay is Sunday then
				set loopCounter to random number from 90 to 120
			else if currentDay is Friday or currentDay is Wednesday then
				set loopCounter to random number from 70 to 100
			else
				set loopCounter to random number from 60 to 80
			end if
		else
			-- 10PM logic
			set outputFile to "/Users/dominicwood/Scripts/SpotifyRepeat10PM.txt"
			if currentDay is Saturday or currentDay is Sunday then
				set loopCounter to random number from 100 to 130
			else
				set loopCounter to random number from 50 to 80
			end if
		end if
		
		-- Capture start time
		set startTime to currentTime
		
		set shuffleCounter to 0
		
		repeat loopCounter times
			set shuffleCounter to shuffleCounter + 1
			set currentTrack to current track
			set trackArtist to artist of currentTrack
			set trackDuration to duration of currentTrack
			
			if trackArtist is not "Latex Wednesday" then
				delay trackDuration
				next track
			else
				-- Check track duration and decide delay
				if trackDuration / 1000 ≤ 31 then
					next track
				else
					delay (30 + (0.05 * (trackDuration / 1000)))
					next track
				end if
			end if
			
			-- Record the track name and count
			set trackName to name of currentTrack
			if trackNameList contains trackName then
				-- Increase count for existing track
				set trackIndex to my indexOf(trackNameList, trackName)
				set item trackIndex of trackCountList to (item trackIndex of trackCountList) + 1
			else
				-- Add new track to the list
				set end of trackNameList to trackName
				set end of trackCountList to 1
			end if
			
			-- Reset shuffle every N iterations
			if shuffleCounter mod (random number from 1 to 10) = 0 then
				if shuffling is true then
					set shuffling to false
					set shuffling to true
				else
					set shuffling to true
					set shuffling to false
				end if
			end if
		end repeat
		
		-- Sort the trackNameList and trackCountList by play count in descending order
		repeat with i from 1 to (count trackCountList) - 1
			repeat with j from i + 1 to count trackCountList
				if item j of trackCountList > item i of trackCountList then
					-- Swap in trackCountList
					set temp to item i of trackCountList
					set item i of trackCountList to item j of trackCountList
					set item j of trackCountList to temp
					-- Swap in trackNameList
					set temp to item i of trackNameList
					set item i of trackNameList to item j of trackNameList
					set item j of trackNameList to temp
				end if
			end repeat
		end repeat
		
		-- Capture end time
		set endTime to current date
		
		-- Stop Spotify playback and restore the original volume
		pause
		set sound volume to currentvol
	else
		display dialog "Spotify is not running."
	end if
end tell

-- Function to find the index of an item in a list
on indexOf(theList, theItem)
	repeat with i from 1 to count of theList
		if item i of theList is theItem then return i
	end repeat
	return 0
end indexOf

-- Calculate total track count
set totalTrackCount to 0
repeat with countNumber in trackCountList
	set totalTrackCount to totalTrackCount + countNumber
end repeat

-- Prepare the output with sorted lists
set outputText to "Start Time: " & startTime & "
End Time: " & endTime & "
        
Total Tracks Played: " & totalTrackCount & "
        
Tracks played by 'Latex Wednesday':
"

repeat with i from 1 to count of trackNameList
	set outputText to outputText & item i of trackNameList & ": " & item i of trackCountList & "
"
end repeat

-- Write to the file
do shell script "echo " & quoted form of outputText & " > " & quoted form of outputFile

-- Send the relevant information by email
tell application "Mail"
	set theMessage to make new outgoing message with properties {subject:"Spotify Playlist Report", content:outputText}
	tell theMessage
		make new to recipient at end of to recipients with properties {address:"domjwood@gmail.com"}
	end tell
	send theMessage
end tell