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().
plist=player.GetAll()
function findplayer(name)
updatePlayerList()
table.foreach(plist,function(k,v) if v:GetName()==name then return v end end)
print("could not find player with given name "..name.." !")
end
function updatePlayerList()
plist=player.GetAll()
end
function spawn(player,command,args)
findplayer(args[1]):Spawn()
print("attempted to spawn player ".. args[1])
end
concommand.Add("_spawn",spawn)
However, when I try to execute both
_spawn “Username”
and
_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()?
Fixed!
I was using table.foreach(), which doesn’t appear to work.
using the for k,v in pairs(plist) worked perfectly.