I wrote the $randuser script. It's designed to select a random
active user in chat, as I prefer to not have lurkers being called out in chat randomly as that is a huge no-no on Twitch. It also relies on other variables that are created from other scripts that I designed (%streamer, %mychan, etc). It looks like you tried to dissect the randuser script and to maroon's point, you made several errors trying to do so. If you don't care if the user has been active or not, than JohnEricNO's one line suggestion sounds like a perfect solution for your needs. Otherwise, it's probably going to take a bit more effort and work on your part to only have your script select active users.

I did take some time and had a look back at the last edit of the randuser script, and it shouldn't be too difficult to have your bot only select active users. The default is 900 seconds (15 minutes), which means that a user had to have said something or done an action in the last 15 minutes to be eligible to be chosen randomly. Just /set %activetime to whatever you want the time to be (in seconds), and /set %mychan to your channel name (or just manually edit your channel name in). You can then use something like:
ON *:TEXT:!slap:#troyl: MSG $chan $nick slaps $randuser $+ .
Added lines in the original code to make the randuser script (hopefully) work now without anything else:
ON *:LOAD: {
IF (!%activetime) SET %activetime 900
IF (!$hget(activeusers)) HMAKE activeusers
IF (!%commonbots) SET %commonbots moobot nightbot revlobot vivbot xanbot wizebot streamelements
}
ON *:CONNECT: IF (($server == tmi.twitch.tv) && (!$hget(activeusers))) HMAKE activeusers
alias randuser {
VAR %x = 1
WHILE ($hget(activeusers, %x).item != $null) {
VAR %nick $v1
IF (!$1) { IF ((%nick ison %mychan) || ($calc($hget(activeusers, %nick) + 90) >= %activetime)) VAR %activelist %activelist %nick }
ELSEIF ($1 == other) { IF (((%nick ison %mychan) || ($calc($hget(activeusers, %nick) + 90) >= %activetime)) && (%nick != $nick)) VAR %activelist %activelist %nick }
ELSEIF ($1 == notme) { IF (((%nick ison %mychan) || ($calc($hget(activeusers, %nick) + 90) >= %activetime)) && (%nick != %streamer)) VAR %activelist %activelist %nick }
ELSEIF ($1 == othernotme) { IF (((%nick ison %mychan) || ($calc($hget(activeusers, %nick) + 90) >= %activetime)) && (%nick != %streamer) && (%nick != $nick)) VAR %activelist %activelist %nick }
ELSEIF ($1 == list) { IF ((%nick ison %mychan) || ($calc($hget(activeusers, %nick) + 90) >= %activetime)) VAR %activelist %activelist %nick }
ELSE BREAK
INC %x
}
IF ($1 == list) RETURN %activelist
ELSE {
VAR %randuser $gettok(%activelist, $rand(1, $numtok(%activelist, 32)), 32)
IF (%randuser != $null) RETURN %randuser
ELSE RETURN $nick
}
}
ON *:TEXT:*:%mychan:IF (($nick != twitchnotify) && ($nick != $me) && (!$istok(%commonbots,$nick,32))) activeusers
ON *:ACTION:*:%mychan:IF (($nick != twitchnotify) && ($nick != $me) && (!$istok(%commonbots,$nick,32))) activeusers
alias activeusers HADD -mz activeusers $nick %activetime