Why is my script editor coming up with connection invalid after running it for a while?
For a double-click every 5 seconds, until you quit the script, try just

delay 3  
tell application "RuneScape" to activate  
repeat  
    delay 5  
    tell application "System Events"  
        keystroke (key code 83)  
        keystroke (key code 83)  
    end tell  
end repeat