Ingame Spam Message

Made this quite a while ago, didn’t think about adding it to this, what do u guys think of it? It works great for the majority of games.

set Yourgame to "Your Game" --> Change YourGame to Your game's name <--
set Spammsg to text returned of (display dialog "Say What..?" default answer "")
set the clipboard to Spammsg
repeat
	set spamtimes to text returned of (display dialog "How Many Times?" default answer "")
	try
		set spamtimes to spamtimes as number
		exit repeat
	on error
		beep
	end try
end repeat
tell application Yourgame
	activate
end tell
tell application "System Events"
	repeat spamtimes times
		key down return
		key up return
		keystroke (the clipboard)
		key down return
		key up return
	end repeat
end tell