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

How do I refer to players of one team?

Asked by 9 years ago

How do I use only players of one team in a script?

For example, the team name is "Fighters" and I want to use a function that teams anyone in that team back to Spectators if Fighters has one or less player. If one player then announce the winner, if 0 then announce a tie.

Fight = game.Workspace.Fight.Value
GameVal = game.Workspace.GameVal.Value
Fighters = game.Teams.Fighters:GetChildren()

function finish()
    if GameVal == true and #Fighters == 1 then
        Fighter = Fighters.FindFirstChild.Name
        m = Instance.new("Hint")
        m.Parent = game.Workspace
        m.Text = Fighter.."has won the round!"
        GameVal = false
        wait(3)
        m:remove()
    elseif GameVal == true and #Fighters == 0 then
        m = Instance.new("Hint")
        m.Parent = game.Workspace
        m.Text = "There has been a tie!"
        wait(3)
        m:remove()
    end
end

Fight.Changed:connect(finish)

Will this work or how should I approach this?

1 answer

Log in to vote
1
Answered by
hudzell 238 Moderation Voter
9 years ago
Fight = game.Workspace.Fight.Value
GameVal = game.Workspace.GameVal.Value
Fighters = game.Teams.Fighters:GetChildren()

function finish()
    Fighters = game.Teams.Fighters:GetChildren() --Re-Defining Fighters value
    if GameVal == true and #Fighters == 1 then
        Fighter = Fighters --Since there is only one player, it's getting all the children in Fighters, which is just that one player
        m = Instance.new("Hint")
        m.Parent = game.Workspace
        m.Text = Fighter.Name.." has won the round!" --Inserted a space, would have looked like this "Player1has won the round!", also you forgot to have it get the fighter's name, you were trying to get the fighter's player object
        GameVal = false
        wait(3)
        m:remove()
    elseif GameVal == true and #Fighters == 0 then
        m = Instance.new("Hint")
        m.Parent = game.Workspace
        m.Text = "There has been a tie!"
        wait(3)
        m:remove()
    end
end

Fight.Changed:connect(finish)

Try it and tell me how it works! :D

0
Oh okay I need another script to work first, can you tell me whether trying to change the team of a whole team works? Like I am trying PureDefiance 20 — 9y
0
player = game.Players:GetChildren() player.TeamColor = BrickColor.new("Bright green") would that work? Because its not for me. PureDefiance 20 — 9y
Ad

Answer this question