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

(Part 2) How could I fix my place player in team script?

Asked by 8 years ago

Hello again :3

So the script that I have is supposed to make some equal teams..

Wait, take a look at the script first :

local redready = true

while true do -- loop
wait(1) -- waits

  for _,player in pairs(game.Players:GetChildren()) do -- Loop trough all players
    if player.TeamColor == BrickColor.new("Medium stone grey") then

    if redready == true 
        then
                   redready = false                
                   player.TeamColor = BrickColor.new("Really red")
            end

    elseif redready == false
        then
                   redready = true                     
                   player.TeamColor = BrickColor.new("Cyan")
end
end
end

I have no clue why this is not working ( when I test it, the first player goes into red then he gets moved to blue, then everyone else goes into the red team )

Thanks for the help!

2 answers

Log in to vote
1
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

You close your if with an end before it can reach the elseif, you dont do that.

i removed the first end because you shouldn't close your if before you reach the end. an elseif is part of the if, therefor it shouldn't be closed at that point.

local redready = true

while true do
wait(1)
    for _,player in pairs(game.Players:GetChildren()) do -- Loop trough all players
        if player.TeamColor == BrickColor.new("Medium stone grey") then
            if redready == true then
                redready = false                
                player.TeamColor = BrickColor.new("Really red")
            --removed end
            elseif redready == false then
                redready = true                     
                player.TeamColor = BrickColor.new("Cyan")
            end -- it should be closed here, since elseif is part of the if.
        end
    end
end
Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

This is use in my game Swords and stuff scripted by me! https://www.roblox.com/games/571957768/ASAS

local function Random()
    local plays = game.Players:GetChildren()
    for i = 1, #plays do
            print(plays[i].Name)
            --Players[i].TeamColor = BrickColor.new()
            if TC == 2 then
                plays[i].TeamColor = BrickColor.new("Bright blue")
                TC = 1
            else
                plays[i].TeamColor = BrickColor.new("Bright red")
                TC = 2
            end
    end
end

that or in your code

local redready = true

while true do -- loop
wait(1) -- waits

  for _,player in pairs(game.Players:GetChildren()) do -- Loop trough all players
    if player.TeamColor == BrickColor.new("Medium stone grey") then
     if redready == true then
                   redready = false                
                   player.TeamColor = BrickColor.new("Really red")
      else
                   redready = true                     
                   player.TeamColor = BrickColor.new("Cyan")
end
end
end
end

Answer this question