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

This gamecontroller script doesn't team players. Why?

Asked by 9 years ago

This script changes values, and a script in the starterGUI checks their values. Here the script in workspace;

-- Scripted by adspace44
numberOfPlayers = 0 -- Variable for the amount of players on the server
gameInProgress = script.gameInProgress -- value for game in progress
gameWillStart = script.gameWillStart -- value for game starting... meant for pickin teams etc
teamLobby = script.teamLobby
-- Local variables
local Players = game:GetService("Players")

function gameplay()
    print("Game has started, T-I-M-E has been picked")
    wait(180) -- round length
    print("test 1")
    teamLobby.Value = true
    wait(5)
    teamLobby.Value = false
    gameInProgress.Value = false
    check() -- Reruns everything from top to bottom
end
function picktime() -- Picks new player
    local randomPlayer = game.Players:GetPlayers ()[math.random (1,game.Players.NumPlayers)]
    randomPlayer.TeamColor = BrickColor.new("White")
    gameplay()
end
function check() -- Checks if the game is able to start
    if numberOfPlayers >= 3 then -- if the number of players is equal to or greater than 3
        if gameInProgress.Value == false then -- Check if the game is already started
            print("Game is able to start!") -- if it isn't, then start the game
            gameWillStart.Value = true
            wait(10) 
            gameWillStart.Value = false -- Disables the value for next time
            gameInProgress.Value = true -- Disables this whole block of code
            picktime() 
        end
    end
end
function onPlayerJoin()
    numberOfPlayers = numberOfPlayers + 1 -- Number of players + 1
    print(numberOfPlayers) -- Prints
end
function onPlayerLeave()
    numberOfPlayers = numberOfPlayers - 1 -- Total amount of players - 1
    print(numberOfPlayers) -- Prints
end
while true do
    check()
    wait(1)
end

Players.PlayerAdded:connect(onPlayerJoin)
Players.PlayerRemoving:connect(onPlayerLeave)

hierarchy of script; http://gyazo.com/d8ec5c2e5c65d0a78afdfaef5f2c01d3

script in StarterGUI -

gameWillStart = game.Workspace.Gamecontroller.gameWillStart
gameInProgress = game.Workspace.Gamecontroller.gameWillStart
player = script.Parent.Parent



if gameWillStart.Value == true then
    player.TeamColor = BrickColor.new("Camo")
    for i,v in pairs(game.Players:GetPlayers()) do
        v:LoadCharacter()
        print("h")
    end
end

The script is also supposed to team the players BACK to the Hot pink team when the game is over.

The problem is, is that first the players don't get teamed to the team camo, and then a random player isn't chosen to be on the white team. The players also don't get put back into the team lobby when the round is over.

Basically, what I want is this; When there is 3 or more players, team them to the teamcolor "Camo". Then, pick ONE random player to be teamed white. Then, respawn everyone and wait 180 seconds as the players play. Then, team them all lobby and repeat infinity. All the current values are Booleans such as gameWillStart and gameInProgress.

Answer this question