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 a script executes only when a player is in a specific team?

Asked by 4 years ago

How do i make it so a script executes only when a player is in a specific team?

2 answers

Log in to vote
0
Answered by 4 years ago

Replace "Red" with whatever team you're looking for on the "game:GetService("Teams").Red" line

if(player.Team == game:GetService("Teams").Red) then
    ---code
end
Ad
Log in to vote
0
Answered by
Sorukan 240 Moderation Voter
4 years ago
Edited 4 years ago

You have to first set the players in a specific team so to do this, you can create a StringValue in the players when they join the game. This will act as a tag to determine which team they're on in the game. You can then loop through the players with a for loop and check if they have the tag for the specific team. If they do, then run the code for said team.

game.Players.PlayerAdded:Connect(function(players)

    if players.Name == 'Boi' then
        local redTeam = Instance.new('StringValue')
        redTeam.Name = 'RedTeam'
        redTeam.Parent = players
    end


    if players.Name == 'YoBoi1337' then
        local blueTeam = Instance.new('StringValue')
        blueTeam.Name = 'BlueTeam'
        blueTeam.Parent = players 
    end


    for i,v in pairs(players:GetChildren()) do
        if v.Name == 'RedTeam' then
            print('Player is on red team') -- execute the script you want on the red team
        elseif v.Name == 'BlueTeam' then
            print('Player is on blue team') -- execute the script you want on the blue team
        end
    end

end)

0
If you want the teams to show up on the top right corner like a leaderboard, check out this article https://developer.roblox.com/en-us/articles/Leaderboards. It's very similar to the code i just showed you. Sorukan 240 — 4y

Answer this question