Counting Finder Selection

Hi,
I’m working on a script which needs to get the count of files in a finder selection. I tried this, but it returns a count of 0 no matter how many files are in the selection.

tell application “Finder”
set myFileCount to count of items in the selection
set the myFiles to the selection
if the myFiles is {} then
beep
display dialog “Please select items before running this script.” buttons {“Cancel”} default button 1
end if
end tell

Thanks

This might work.

tell application "Finder"
	set selectedItems to selection
end tell

set itemCount to count selectedItems

if itemCount is 0 then
	beep
	display dialog "Please select items before running this script." buttons {"Cancel"} default button 1
end if

Thanks!