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 change teams just by touching a part?

I'm trying to make a script that changes your team when you touch the part

2 answers

✓ Accepted answer

You can use a touched event to detect whenever an object touches the part, then determine whether or not the object is a player, and set their team.

Assuming that the team script is inside of the part:

local team = game.Teams.Team -- replace this with the directory to the team you want

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild('Humanoid') and game.Players:FindFirstChild(hit.Parent.Name) then
		local plr = game.Players[hit.Parent.Name]
		plr.Team = team
	end
end)

Script in part:

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then

	local teamColor = --[[ Put the colour of the team you want the player to be inserted to
					  e.g. Really black, Forest green, Institutional white, etc.
					  Make sure it is a string.]]

	local player = game.Players:GetPlayerFromCharacter(hit.Parent)

	player.TeamColor = BrickColor.new(teamColor)
	
	end
end)

Don't forget to accept the answer if I helped!

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