Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

1 person per spawn?

I would want to take out the permission and add in a 1 person per spawn.

I'm trying to help a friend out here.

print ("1 Person Spawn Script Loaded")


permission = {"NAME"}


function person(name) 
	for i = 1,#permission do 
		if (string.upper(name) == string.upper(permission[i])) then return true end 
	end 
	return false 
end 

function onPlayerEntered(newPlayer) 
	print("Person Spawned") 
	local human = newPlayer:findFirstChild("Backpack") 
	if (human ~= nil ) then
		if (person(human.Parent.Name)) then 
			human.Parent.TeamColor=script.Parent.TeamColor
                end
        end
end

game.Players.ChildAdded:connect(onPlayerEntered)

1 answer

✓ Accepted answer

Under normal circumstances, you never have to worry about this - as long as all the Team instances have AutoAssignable set to true, Roblox will set player teams accordingly.

However, if you ever need a script to assign them, here's this:

local full = false
game.Players.PlayerAdded:connect(function(lplayer)
	for _,team in pairs(game:GetService("Teams"):GetTeams()) do
		local players = game.Players:GetPlayers()
		for _,player in pairs(players) do
			if player ~= lplayer then
				if player.TeamColor == team.TeamColor then full = true --If someone is in selected team, declare it full
			end
		end
		if full = false then --If the team is not full, position the player in it!
			lplayer.TeamColor = team.TeamColor
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.