Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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

Log in to vote
0
Answered by
gitrog 326 Moderation Voter
6 years ago
Edited 6 years ago

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)
0
Explain your code a bit more, I assume there are a few new concepts in there that he should learn. TheDeadlyPanther 2460 — 6y
0
Got it. gitrog 326 — 6y
Ad

Answer this question