Simple LUA issues

I’m starting to make a custom administration mod for my server, because apparently all of them are broken and dysfunctional. (Exsto, Evolve, and ULX not loading commands in)
This is the code I decided to start with, as most of the other commands would revolve around findplayer(name) and updatePlayerList().

function findplayer(name)
table.foreach(plist,function(k,v) if v:GetName()==name then return v end end)
print("could not find player with given name "" !")
function updatePlayerList()
function spawn(player,command,args)
	print("attempted to spawn player ".. args[1])

However, when I try to execute both
_spawn “Username”
_spawn Username
My code returns that it could not find the player specified.
The username matches exactly what it should have been, is there something wrong with my findplayer()?

I was using table.foreach(), which doesn’t appear to work.
using the for k,v in pairs(plist) worked perfectly.

you need to fix your find player function aswell as it doesnt return anything if it doesnt find the player, yet you are calling a userdata method on it.

if you enter in a name which doesnt match to a player you will get errors.

if you make it return false then check if its false when you call it, it should work for anything.