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

How do I do so that when someone is not in the group and joins he get in the team Hot Pink?

How do I do so that when someone is not in the group and joins he get in the team Hot Pink

wait(0.5)
function onPlayerEntered(plyr)
if plyr:IsInGroup(400) then
plyr.TeamColor = BrickColor.new("Persimmon")
end
end

game.Players.PlayerAdded:connect(onPlayerEntered)


2 answers

✓ Accepted answer

You indeed put an extra end. And it puts to neutral because Hot Pink isn't a valid BrickColor. It should be Hot pink. See, the letters case is very important sometimes.

--Auto teams team trainee
wait(0.5)
function onPlayerEntered(plyr)
	plyr.TeamColor = BrickColor.new("Hot pink")--Trainee team colour
end

game.Players.PlayerAdded:connect(onPlayerEntered)

You can also set the AutoAssignable property of the team to true so that you don't need a script for it.

You have an extra end which you do not need.

Also, you should properly indent your code, one indent per scope.

Additionally, use RBXScriptSignal:Connect(), the lowercase version is deprecated.

Worth noting that Player.Team exists now, which is more idiomatic and preferable to setting the player's Player.TeamColor.

No need for a wait(0.5) at the top of your script, you can get rid of that.

Also variables like plyr are a waste to shorten, just call it player, we have autocomplete, typing speed doesn't matter, readability does.

local TeamsService = game:GetService("Teams")

local SpecialGroupId = 92929

local function OnPlayerAdded(Player)
	if Player:IsInGroup(SpecialGroupId) then
		return
	end

	Player.Team = TeamsService.TeamHere
end)

local Players = PlayersService:GetPlayers()

for Index = 1, #Players do
	local Player = Players[Index]

	OnPlayerAdded(Player)
end

game.Players.PlayerAdded:Connect(OnPlayerAdded)

2 comments

0

but when I delete the extra end it makes everyone go in a a neutral team instead of the team color I said

0

No, it has nothing to do with that. It's probably that the game.Players.PlayerAdded event listener hasn't connected by the time you've joined. I'll modify my answer to show you how to get around this.

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