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

How do I change teams just by touching a part? [closed]

Asked by
iiAceMo 50
4 years ago

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

Closed as Not Constructive by cailir and SerpentineKing

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

2 answers

Log in to vote
0
Answered by 4 years ago

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)
Ad
Log in to vote
0
Answered by
DesertusX 435 Moderation Voter
4 years ago
Edited 4 years ago

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!