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

Random Team Script(Supposed to place you in a random team), would it work?

Asked by 10 years ago

Would it execute smoothly? It is supposed to change your team to a random one when the server gets to twenty players.

--[[---Thanks to free-model for helping w/reconstruction.
    & please insert the a number value called "Players" into Teams.
    READ:
    1. Insert NumberValue "Value" straight into this script & insert NumberValue "Players" into Teams.
--]]



A = game.Teams:findFirstChild("TeamName")
B = game.Teams:findFirstChild("TeamName")
C = game.Teams:findFirstChild("TeamName")
D = game.Teams:findFirstChild("TeamName")

function Redo()
    wait(5)
end

    if game.Players.NumPlayers = 20 then
        Assign() else
        Redo()
    end

function Assign()
    A.Players.Value = 0
    B.Players.Value = 0
    C.Players.Value = 0
    D.Players.Value = 0
    teamchosen = false 
    player = game.Players:GetChildren()
    for i = 1, #player do 
        print(player[i])
        if A.players.Value == B.players.Value
            if teamchosen == false then
                script.Value.Value = math.random(1,4)
                if script.Value.Value == 1 then
                    player[i].TeamColor = A.TeamColor
                    teamchosen = true
                    A.Players.Value = A.Players.Value +1
                elseif
                    script.Value.Value ==2 then
                    player[i].TeamColor = B.TeamColor
                    teamchosen = true
                    A.Players.Value = A.Players.Value +1
                elseif
                    script.Value.Value ==3 then
                    player[i].TeamColor = C.TeamColor
                    teamchosen = true
                    A.Players.Value = A.Players.Value +1
                elseif
                    script.Value.Value ==4 then
                    player[i].TeamColor = D.TeamColor
                    teamchosen = true
                    A.Players.Value = A.Players.Value +1
                end
            end
        end
    end
end

Will it work?

1 answer

Log in to vote
0
Answered by
RM0d 305 Moderation Voter
10 years ago

NO there are problems I took your code and made it nicer, here you go


Teams={"Bloxers","Sky Warriors","Sand Archers","Korblox"} --Name of teams you can change it AmountOfPlayersRequired = 20 while true do player = game.Players:GetChildren() wait(1) if #player >= AmountOfPlayersRequired then --waits until players are above or equal to 20 Assign() break end end function Assign() players = game.Players:GetChildren() for i = 1,#players do ChosenTeam = Teams[math.random(1,#Teams)] players[i].TeamColor = game.Teams:findFirstChild(ChosenTeam).TeamColor end end
0
BUMPY BUMP RM0d 305 — 10y
Ad

Answer this question