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

How do I make a team change script that changes upon contact with player?

I can't figure out how to do it. I can get the part to kill on touch, but it won't change the team. Here's what i have so far:

local player= game.Players.LocalPlayer

function onTouch(part) player.TeamColor = BrickColor.new ("Dark stone grey") local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then humanoid.Health = 0 end end

script.Parent.Touched:connect(onTouch)

1 answer

This should work. Put this script in the part you want to change the player's team.

local TeamName = nil --Set this to the name of the team you want the player to be added to, in quotes.

script.Parent.Touched:connect(function(char) --This is a touched event. "char" is the name of the variable which is the part being touched.
	local player = game.Players:GetPlayerFromCharacter(char.Parent) --Get PlayerFromCharacter will get a character, and if there is a player, it will output the player's name. char.Parent means we are getting the parent of the part that hit, which, if it is a player, should be the Player's model.
 
	if player then --This will check if a player was found, and if it does, it will run the following script.
   		player.TeamColor = game.Teams[TeamName].TeamColor --Changes the players team.
		player.Character.Humanoid.Health = 0
	end
end)

2 comments

0

Explain your code a bit more, I assume there are a few new concepts in there that he should learn.

0

Got it.

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