Move To Spectator

I was attempting to make a ulx respawn command for Chessnut Jailbreak, but it would not work. The player would change teams from a dead prisoner/guard to and alive one and teleport to a spawn point. They would not spawn. I searched through the gamemode files and found this:

function GM:ShouldPlayerSpectate()
return JB_ROUND_STATE == ROUND_ACTIVE or JB_ROUND_STATE == ROUND_DEAD or JB_ROUND_STATE == ROUND_END

end

I removed JB_ROUND_STATE == ROUND_ACTIVE. The command worked, but now any player who joins the game will spawn in and players who are killed automatically respawn. I played around with GM:PlayerInitialSpawn and GM:PlayerDeath. I could not figure out how to fix it. How would I make players who are killed or join the server switch to spectator?

in the respawn command do ply:SetTeam()

I already have that in the respawn command.

function ulx.respawn( calling_ply, target_ply )
if target_ply:Team() == TEAM_GUARD_DEAD then
target_ply:Spawn()
target_ply:SetTeam( TEAM_GUARD )
ulx.fancyLogAdmin( calling_ply, true, “#A respawned #T”, target_ply )
elseif target_ply:Team() == TEAM_PRISONER_DEAD then
target_ply:Spawn()
target_ply:SetTeam( TEAM_PRISONER )
ulx.fancyLogAdmin( calling_ply, true, “#A respawned #T”, target_ply )
end
end
local respawn = ulx.command( “RespawnMe”, “ulx respawn”, ulx.respawn, “!respawn” )
respawn:addParam{ type=ULib.cmds.PlayerArg }
respawn:defaultAccess( ULib.ACCESS_ADMIN )
respawn:help( “Respawns a player” )

The problem isn’t the command. It’s the spectator mode.