player.GetAll() Causing issues?

I am trying to create a script that find s a random player.
I have been having problems with player.GetAll() recently and am wondering If I am just being an idiot somewhere…

function ScareRandom()

PrintMessage(HUD_PRINTTALK, "ScareTimerRan")

local victim = table.Random(player.GetAll())

PrintMessage(HUD_PRINTTALK,"Victim chosen: "..victim)

local scares = {1,2}
local scarechoice = table.Random(scares)
PrintMessage(HUD_PRINTTALK,"Scare chosen: "..scarechoice)

if(scarechoice == 1)then

timer.Create("ScareRandomly", 10, 0, ScareRandom)

scaredvoicesMale = {"vo/npc/male01/help01.wav",

function dropWeapon(victim)

It stops printing after “ScareTimerRan” -What could be the issue?

Because it is throwing an error - attempt to concatenate a userdata value.

I think you meant to do this:

PrintMessage( HUD_PRINTTALK, "Victim chosen: " .. victim:Nick( ) )

Tabs help tremendously:

[lua]if ( SERVER ) then
// This doesn’t need to be global
local scaredvoicesMale = {

function dropWeapon( victim )
	victim:StripWeapons( );
	victim:EmitSound( table.Random( scaredvoicesMale ), 100, 100 ); -- Audio volume needed

function ScareRandom( )
	PrintMessage( HUD_PRINTTALK, "ScareTimerRan" );

	local victim = table.Random( player.GetAll( ) );

	PrintMessage( HUD_PRINTTALK, "Victim chosen: " .. ( IsValid( victim ) && victim:Nick( ) || "NO_NAME" ) ); -- Ternary operation to ensure no errors

	local scarechoice = math.random( 1, 2 ); -- No need to do table.Random when math.random uses whole numbers...
	PrintMessage( HUD_PRINTTALK,"Scare chosen: " .. scarechoice );

	if ( scarechoice == 1 ) then
		dropWeapon( victim );


timer.Create( "ScareRandomly", 5, 5, ScareRandom );


few issues here and there.

Ah Thank you everyone… I wasn’t able to use NotePad++ and that really threw me off.


Why can’t you use it???

Enable GMod Lexer in addons, restart NP++ twice, close it, pop this in %appdata%/notepad++/addons/config/

And you’ll have the most up to highlighting date file.

Also, please mark this thread solved in the upper left corner to avoid confusion :slight_smile:

Oh no I meant I was using a device that didn’t have it.

I have all of that on my pc.

Thanks though!