How can i make a script that force a spectator to spawn in the server by Lua code?
Like first, setplayers team = Random(1,2)
Then spawn the player...
Scripts
Force specator to spawn
Force specator to spawn
1

addhook("join","onJoin")
function onJoin(id)
	if (math.random(0,2) >= 1)
		parse('maket '..id)
	else
		parse('makect '..id)
	end
end
addhook("join", "_join")
function _join(id)
	-- forceRandomTeamRespawn when they join the server
	forceRandomTeamRespawn(id)
end
addhook("team", "teamselect")
function teamselect(id, team)
	if team == 0 then -- if they join spec, forceRandomTeamRespawn then
		forceRandomTeamRespawn(id)
	end
end
function forceRandomTeamRespawn(id)
	-- have them join a random team
	local team = math.random(1,2)
	if team == 1 then
		parse('maket '..id)
	else
		parse('makect '..id)
	end
	-- spawn them
	parse('spawnplayer '..id)
end
Nekomata:'s answer is better because he contemplates the case when the player joins spectator after joining the game. Also, I thought math.random(a,b) returned a real number between a and b (I misread the documentation).
1
