Stopping events timing out problem “Apple Event Timed Out”.

I have several events that get triggered by an Application called “Scheduler”. However sometimes I get massages that they time out. Below is one that times out on me. It is saved as an application. And in the Security Panel all preferences are set properly as it runs fine if I manually trigger it.

The first bit checks if we have a network, I added the spoken text etc. to hear if it is working since it is a server that runs the application. (Mac Mini)
OS 11.6.1)

-- check if network is up
set networkUp to false
repeat until networkUp is true
		do shell script "ping -o -t 5"
		set networkUp to true
	on error
		delay 0.5
		say "Couldn't connect, no network"
		delay 1
		delay 5 -- something went wrong, so try again in 5 seconds
	end try
end repeat
delay 0.5
say "Connected"

-- end

set myDateString to (weekday of (current date) as text) & " " & ((day of (current date)) as text) & " " & ((month of (current date)) as text) & " " & ((year of (current date)) as text) & (" - text") --change me
set theSubject to myDateString

set RN to random number from 1 to 6
set theBody to item RN of {"Message 1,

", "Message 2, 

", "Message 3,

  ", "Message 4,
", "Message 5,

", "Message 6,


set theTarget to ""
tell application "Mail"
	set newMessage to make new outgoing message with properties {subject:theSubject, content:theBody}
	tell newMessage
		make new to recipient at end of to recipients with properties {address:theTarget}
		set sender to "Test <>"
	end tell
	delay 10
	send newMessage
end tell

anybody has an idea as to how to fix this? Or what could be wrong?