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

How do I make it so if a player in a specific team touches this block , it changes their team ?

Asked by 5 years ago

Hello , I am trying to make it so if a player in the 'Prisoner' team (only) hits the block it will change their team to 'Criminal' . Heres what ive attempted so far: (Bare with me , I am pretty new to coding) Help would be greatly appreciated:)

function Touch(hit)
    for i,v in pairs(game.Teams["Prisoner"]:GetPlayers())do
        player.Team = game.Teams.Criminal 
    end
end)
0
If Player.Team == game.Teams.Prisoner then Player.Team = game.Teams.Criminal theking48989987 2147 — 5y

1 answer

Log in to vote
0
Answered by
blockmask 374 Moderation Voter
5 years ago

Ok, you need to understand the basics of the Touched event in order to continue. So, first of all, you want to check if it's a humanoid that touched it, and only players and NPCs have humanoids, so you have a 50/50 chance of it being a player. And now you want to check if the humanoid is a child of the player's character, then check what team they're in, and set the team to the specified team you'd like

local Teams = game:GetService("Teams")

function Touched(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            local ChangedTeam = "Prisoner"
            if player.Team ~= Teams[ChangedTeam] then
                player.Team = Teams[ChangedTeam]
            end
        end
    end
end

Part.Touched:Connect(Touched)
0
wym there's a 50 50 chance of being an npc or a player theking48989987 2147 — 5y
0
Where would I input what team the prisoner will change to (criminal in this case) ? Enzo341 4 — 5y
0
Yeah, simply change "Prisoner" to "Criminal" blockmask 374 — 5y
0
And please accept if this helped blockmask 374 — 5y
Ad

Answer this question