Alright you asked then.
Main Script
--Game Starting
local GameStatus = script.Parent.GameStatus
local TotalPlrs = 2
local RE = game:GetService('ReplicatedStorage'):WaitForChild('ChangeTrans')
local CourtGui = script.Parent:FindFirstChild("ScoreGui",true)
local function TotalPlayers()
local numberofplayers = 0
for _,v in pairs (script.Parent.QueuePlayers:GetChildren()) do
if v:IsA("ObjectValue") and v.Value ~= nil then
numberofplayers = numberofplayers + 1
end
end
for _,v in pairs (script.Parent.Players:GetChildren()) do
if v:IsA("ObjectValue") and v.Value ~= nil then
numberofplayers = numberofplayers + 1
end
end
return numberofplayers
end
GameStatus.GameReady:GetPropertyChangedSignal("Value"):Connect(function()
local GameReady = GameStatus.GameReady
if GameReady.Value == true then
repeat wait()
until TotalPlayers() == TotalPlrs
if TotalPlayers() == TotalPlrs then
wait(3)
GameStatus.StartGame:Fire() -- Start the Game
end
end
end)
--Break Prevention
--Queue System
local function CheckIfCurrentPlayer(player)
local CurrentPlayer = false
for _,v in pairs (script.Parent.QueuePlayers:GetChildren()) do
if v.Value == player then
CurrentPlayer = true
end
end
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == player then
CurrentPlayer = true
end
end
return CurrentPlayer
end
local TeamPads = script.Parent.Queue:GetChildren()
for _, queuepad in pairs (TeamPads) do
if queuepad:IsA("BasePart") then
queuepad.ClickDetector.MouseClick:Connect(function(player)
if queuepad.Occupied.Value == false and CheckIfCurrentPlayer(player) == false and script.Parent.Players:FindFirstChild(queuepad.Name).Value == nil and GameStatus.GameReady.Value == true then
queuepad.Occupied.Value = true
local Pad = script.Parent.QueuePlayers:FindFirstChild(queuepad.Name)
Pad.Value = player
local character = player.Character
character.HumanoidRootPart.CFrame = CFrame.new(queuepad.Position + Vector3.new(0,2,0)) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
character.Humanoid.WalkSpeed = 0
wait(1)
character.HumanoidRootPart.Anchored = true
local function getData(player)
if queuepad.Occupied.Value == true then
local arrowPart = game.Workspace["[FIRST]1v1"].Queue.Player1.arrowPart.Decal
arrowPart.Transparency = 1
end
end
RE.OnServerEvent:Connect(getData)
--Hop Off Gui
local HopOff = script.HopOff:Clone()
HopOff.Parent = player.PlayerGui
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.TeamPad.Value = queuepad
local function pressedInputed()
local arrowPart = game.Workspace["[FIRST]1v1"].Queue.Player1.arrowPart.Decal
if arrowPart.Transparency == 0 then
arrowPart.Transparency = 1
elseif arrowPart.Transparency == 0 then
arrowPart.Transparency = 1
end
end
script.Parent.Queue.Player1.ClickDetector.MouseClick:Connect(pressedInputed)
elseif GameStatus.GameReady.Value == false and CheckIfCurrentPlayer(player) == false and queuepad.Occupied.Value == false then
if queuepad.Name == "Player2" then
queuepad.Occupied.Value = true
local Pad = script.Parent.QueuePlayers:FindFirstChild(queuepad.Name)
Pad.Value = player
local character = player.Character
character.HumanoidRootPart.CFrame = CFrame.new(queuepad.Position + Vector3.new(0,2,0)) * CFrame.Angles(math.rad(0), math.rad(90), math.rad(0))
character.Humanoid.WalkSpeed = 0
wait(1)
character.HumanoidRootPart.Anchored = true
--Hop Off Gui
local HopOff = script.HopOff:Clone()
HopOff.Parent = player.PlayerGui
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.TeamPad.Value = queuepad
end
end
end)
end
end
script.Parent.Queue.Player2.Occupied:GetPropertyChangedSignal("Value"):Connect(function()
if script.Parent.Queue.Player2.Occupied.Value == false then
wait(1)
end
end)
-- Prevents it from glitching out
GameStatus.GameReady.Value = true
local Team1 = {} local Team2 = {} local CombinedTeams = {} local PossessionTeam = "Team1" -- Team Tables
local GameEvent = GameStatus.GameEvent
function SpawnBall(BallSpawn)
local FindBall = nil
for _, ball in pairs (game.Workspace:GetDescendants()) do
if ball.Name == "Basketball" or ball.Name == "Basketball1" then
if ball:IsA("Tool") and ball.CourtValue.Value == script.Parent then
FindBall = true
end
end
end
if FindBall ~= true then
PossessionTeam = nil
local ball = game.ReplicatedStorage.Basketball:Clone()
ball.CourtValue.Value = script.Parent
ball.Handle.CFrame = CFrame.new(BallSpawn)
ball.Parent = game.Workspace
end
end
function RemoveBallScripts()
print("Removing Ball Scripts")
for _,v in pairs (game.Workspace:GetDescendants()) do
if v.Name == "Basketball" and v:IsA("Tool") and v.CourtValue.Value == script.Parent then
v.Name = "Basketball1"
GameStatus.ShotClock.On.Value = false
end
end
end
function RemoveBall()
print("Removing Ball from".. script.Parent.Name)
for _,v in pairs (game.Workspace:GetDescendants()) do
if v.Name == "Basketball" or v.Name == "Basketball1" then
if v:IsA("Tool") and v.CourtValue.Value == script.Parent then
print(v.CourtValue.Value)
if game.Players:FindFirstChild(v.Parent.Name) then
local char = v.Parent
if char:FindFirstChild("Ball") then
char.Ball:Destroy()
end
for _, animation in pairs (char.Humanoid:GetPlayingAnimationTracks()) do
animation:Stop()
end
if game.Players:FindFirstChild(v.Parent.Name) then
local plr = game.Players:FindFirstChild(v.Parent.Name)
plr.PlayerGui.PowerGui.Enabled = false
end
end
if v.CourtValue.Value == script.Parent then
v:Destroy()
GameStatus.ShotClock.On.Value = false
end
end
end
end
end
--Function to Teleport Teams
local function TeleportTeams(Team)
if Team == "Team1Ball" then
for _,v in pairs (Team1) do
if game.Players:FindFirstChild(v.Name) then --Confirms Player is still in game
v.Character.HumanoidRootPart.Anchored = false
v.Character.Humanoid.WalkSpeed = 0
v.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team1Spawn.Position)
end
end
for _,v in pairs (Team2) do
if game.Players:FindFirstChild(v.Name) then --Confirms Player is still in game
v.Character.HumanoidRootPart.Anchored = false
v.Character.Humanoid.WalkSpeed = 0
v.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team2Spawn.Position)
end
end
wait(1.9)
SpawnBall(script.Parent.TeamSpawns.Team1Spawn.Position)
wait(.1)
for _,v in pairs (CombinedTeams) do
if game.Players:FindFirstChild(v.Name) then
v.Character.Humanoid.WalkSpeed = 16
end
end
elseif Team == "Team2Ball" then
for _,v in pairs (Team2) do
if game.Players:FindFirstChild(v.Name) then --Confirms Player is still in game
v.Character.HumanoidRootPart.Anchored = false
v.Character.Humanoid.WalkSpeed = 0
v.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team1Spawn.Position)
end
end
for _,v in pairs (Team1) do
if game.Players:FindFirstChild(v.Name) then --Confirms Player is still in game
v.Character.HumanoidRootPart.Anchored = false
v.Character.Humanoid.WalkSpeed = 0
v.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team2Spawn.Position)
end
end
wait(1.9)
SpawnBall(script.Parent.TeamSpawns.Team1Spawn.Position)
wait(.1)
for _,v in pairs (CombinedTeams) do
if game.Players:FindFirstChild(v.Name) then
v.Character.Humanoid.WalkSpeed = 16
end
end
end
PossessionTeam = nil
end
--Whistle
function Whistle()
script.Parent.TeamSpawns.Team1Spawn:FindFirstChild("Whistle"):Play()
end
--WalkSpeed Reset
function WalkSpeed()
for _,v in pairs (CombinedTeams) do
if game.Players:FindFirstChild(v.Name) then
v.Character.Humanoid.WalkSpeed = 16
end
end
end
--Teleporting Teams and Give ball to team
GameEvent.Event:Connect(function(Action)
if Action == "Team1Ball" then
TeleportTeams(Action)
elseif Action == "Team2Ball" then
TeleportTeams(Action)
end
end)
--[[
Scoring Events
]]
--Normal Scoring
GameEvent.Event:Connect(function(Action, Team, Points, ScorePlayer)
if Action == "Scored" then
if Team == "Team1" then
local Team = nil
for _, check in pairs (Team2) do
if check.Name == ScorePlayer then
Team = true
end
end
if Team ~= true then
GameStatus.Team1Score.Value = GameStatus.Team1Score.Value + Points
GameStatus.ShotClock.On.Value = false
GameEvent:Fire("UpdateScores")
for _, v in pairs (CombinedTeams) do
game.ReplicatedStorage.ScoreFoul:FireClient(v, "score")
end
wait(2)
RemoveBall()
wait()
GameEvent:Fire("Team2Ball")
end
elseif Team == "Team2" then
local Team = nil
for _, check in pairs (Team1) do
if check.Name == ScorePlayer then
Team = true
end
end
if Team ~= true then
GameStatus.Team2Score.Value = GameStatus.Team2Score.Value + Points
GameStatus.ShotClock.On.Value = false
GameEvent:Fire("UpdateScores")
for _, v in pairs (CombinedTeams) do
game.ReplicatedStorage.ScoreFoul:FireClient(v, "score")
end
wait(2)
RemoveBall()
wait()
GameEvent:Fire("Team1Ball")
end
end
end
end)
--One Net Scoring
GameEvent.Event:Connect(function(Action, Player, Points)
if Action == "OneNetScored" then
local function findPlayerTeam()
local team = nil
for _, v in pairs (Team1) do
if v.Name == Player then
team = "Team1"
end
end
if team == nil then
for _, v in pairs (Team2) do
if v.Name == Player then
team = "Team2"
end
end
end
return team
end
if findPlayerTeam() == "Team1" then
GameStatus.Team1Score.Value = GameStatus.Team1Score.Value + Points
GameStatus.ShotClock.On.Value = false
GameEvent:Fire("UpdateScores")
for _, v in pairs (CombinedTeams) do
game.ReplicatedStorage.ScoreFoul:FireClient(v, "score")
end
RemoveBallScripts()
wait(2)
RemoveBall()
wait()
GameEvent:Fire("Team1Ball")
elseif findPlayerTeam() == "Team2" then
GameStatus.Team2Score.Value = GameStatus.Team2Score.Value + Points
GameStatus.ShotClock.On.Value = false
GameEvent:Fire("UpdateScores")
for _, v in pairs (CombinedTeams) do
game.ReplicatedStorage.ScoreFoul:FireClient(v, "score")
end
RemoveBallScripts()
wait(2)
RemoveBall()
wait()
GameEvent:Fire("Team2Ball")
end
end
end)
--Visibility
GameEvent.Event:Connect(function(Action)
if Action == "ScoreboardVisibility" then
CourtGui.Enabled = not CourtGui.Enabled
for _, plr in pairs (CombinedTeams) do
if game.Players:FindFirstChild(plr.Name) then
local ScoreGui = plr.PlayerGui.ScoreGui
if ScoreGui.Enabled == true then
ScoreGui.Enabled = false
else
ScoreGui.Enabled = true
end
end
end
end
end)
--Updating Scores
GameEvent.Event:Connect(function(Action)
if Action == "UpdateScores" then
print("Updating Scores")
CourtGui.board.Background.Team1.Text = GameStatus.Team1Score.Value
CourtGui.board.Background.Team2.Text = GameStatus.Team2Score.Value
for _, plr in pairs (CombinedTeams) do
if game.Players:FindFirstChild(plr.Name) then
local ScoreGui = plr.PlayerGui.ScoreGui
ScoreGui.board.Background.Team1.Text = GameStatus.Team1Score.Value
ScoreGui.board.Background.Team2.Text = GameStatus.Team2Score.Value
end
end
end
end)
-- ShotClock Handling
local ShotClockValue = GameStatus.ShotClock:FindFirstChild("On")
local ShotClock = GameStatus:FindFirstChild("ShotClock")
--Ticker
local AlreadyOn = false
ShotClockValue:GetPropertyChangedSignal("Value"):Connect(function()
if GameStatus.ShotClock:FindFirstChild("On").Value == true and AlreadyOn == false then
AlreadyOn = true
while true do
wait(1)
if ShotClock.Value >0 then
if GameStatus.ShotClock:FindFirstChild("On").Value == false or ShotClock.Value <=0 then AlreadyOn = false break end
ShotClock.Value = ShotClock.Value - 1
end
end
end
end)
--ShotClock Update
GameStatus.ShotClock:GetPropertyChangedSignal("Value"):Connect(function()
CourtGui.board.clockTimer.Text = tostring(GameStatus.ShotClock.Value)
for _, plr in pairs (CombinedTeams) do
if game.Players:FindFirstChild(plr.Name) then
local ScoreGui = plr.PlayerGui.ScoreGui
ScoreGui.ShotClock:Fire(GameStatus.ShotClock.Value)
end
end
end)
GameStatus.ShotClock:GetPropertyChangedSignal("Value"):Connect(function()
if GameStatus.ShotClock.Value <=0 then
GameStatus.ShotClock:FindFirstChild("On").Value = false
RemoveBall()
for _, v in pairs (CombinedTeams) do
game.ReplicatedStorage.ScoreFoul:FireClient(v, "violation")
end
Whistle()
if PossessionTeam == "Team1" then
GameEvent:Fire("Team2Ball")
else
GameEvent:Fire("Team1Ball")
end
end
end)
--Possession Change
GameEvent.Event:Connect(function(Action, Player)
if Action == "PossessionChange" then
local function findPlayerTeam()
local team = nil
for _, v in pairs (Team1) do
if v.Name == Player then
team = "Team1"
end
end
if team == nil then
for _, v in pairs (Team2) do
if v.Name == Player then
team = "Team2"
end
end
end
return team
end
if findPlayerTeam() == "Team1" and PossessionTeam ~= "Team1" then
PossessionTeam = "Team1"
ShotClock.Value = 24
GameStatus.ShotClock:FindFirstChild("On").Value = true
elseif findPlayerTeam() == "Team2" and PossessionTeam ~= "Team2" then
PossessionTeam = "Team2"
ShotClock.Value = 24
GameStatus.ShotClock:FindFirstChild("On").Value = true
elseif findPlayerTeam() == "Team1" and PossessionTeam == "Team1" then
GameStatus.ShotClock:FindFirstChild("On").Value = true
elseif findPlayerTeam() == "Team2" and PossessionTeam == "Team2" then
GameStatus.ShotClock:FindFirstChild("On").Value = true
end
end
end)
--StealBall
GameEvent.Parent.StealBallEvent.Event:Connect(function(Action, Player, StealingPlayer, Ball)
print("Ball steal")
if Action == "StealBall" then
local function findPlayerTeam(plr)
local team = nil
for _, v in pairs (Team1) do
if v.Name == plr then
team = "Team1"
end
end
if team == nil then
for _, v in pairs (Team2) do
if v.Name == plr then
team = "Team2"
end
end
end
return team
end
local playerteam = findPlayerTeam(Player.Name)
local stealingplayerteam = findPlayerTeam(StealingPlayer.Name)
if stealingplayerteam ~= playerteam then
Ball.Parent = StealingPlayer
end
end
end)
--OutofBounds
GameEvent.Event:Connect(function(Action)
if Action == "OutofBounds" then
Whistle()
for _, v in pairs (CombinedTeams) do
game.ReplicatedStorage.ScoreFoul:FireClient(v, "foul")
end
if PossessionTeam == "Team1" then
RemoveBall()
wait(2)
GameEvent:Fire("Team2Ball")
else
RemoveBall()
wait(2)
GameEvent:Fire("Team1Ball")
end
end
end)
--Travel Handle
GameEvent.Event:Connect(function(Action, Player)
if Action == "Travel" then
Whistle()
local function findPlayerTeam()
local team = nil
for _, v in pairs (Team1) do
if v.Name == Player then
team = "Team1"
end
end
if team == nil then
for _, v in pairs (Team2) do
if v.Name == Player then
team = "Team2"
end
end
end
return team
end
for _, v in pairs (CombinedTeams) do
game.ReplicatedStorage.ScoreFoul:FireClient(v, "travel")
end
if findPlayerTeam() == "Team1" then
RemoveBall()
GameStatus.ShotClock.On.Value = false
wait(2)
GameEvent:Fire("Team2Ball")
elseif findPlayerTeam() == "Team2" then
RemoveBall()
GameStatus.ShotClock.On.Value = false
wait(2)
GameEvent:Fire("Team1Ball")
end
end
end)
--Team Winning
GameStatus.Team1Score:GetPropertyChangedSignal("Value"):Connect(function()
if GameStatus.Team1Score.Value >=21 then
wait()
RemoveBall()
WalkSpeed()
local Players = script.Parent.Players
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
if Players.Player2.Value ~= nil then
Players.Player2.Value.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Queue.Player1.Position)
Players.Player2.Value.leaderstatsFolder.Losses.Value = Players.Player2.Value.leaderstatsFolder.Losses.Value + 1
end
GameEvent:Fire("ScoreboardVisibility")
Players.Player2.Value = nil
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
Team1 = {} Team2 = {} CombinedTeams = {}
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
elseif v.Value ~= nil then
v.Value.leaderstatsFolder.Wins.Value = v.Value.leaderstatsFolder.Wins.Value + 1
end
end
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Parent = hpf.Value.PlayerGui
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.TeamPad.Value = queuepad
end
end
wait(3)
RemoveBall()
wait(7)
RemoveBall()
end
end)
GameStatus.Team2Score:GetPropertyChangedSignal("Value"):Connect(function()
if GameStatus.Team2Score.Value >=21 then
wait()
RemoveBall()
WalkSpeed()
local Players = script.Parent.Players
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
if Players.Player1.Value ~= nil then
Players.Player1.Value.Character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Queue.Player1.Position)
Players.Player1.Value.leaderstatsFolder.Losses.Value = Players.Player1.Value.leaderstatsFolder.Losses.Value + 1
end
GameEvent:Fire("ScoreboardVisibility")
Players.Player1.Value = Players.Player2.Value Players.Player2.Value = nil
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
Team1 = {} Team2 = {} CombinedTeams = {}
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.Parent = hpf.Value.PlayerGui
HopOff.TeamPad.Value = queuepad
end
end
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
elseif v.Value ~= nil then
v.Value.leaderstatsFolder.Wins.Value = v.Value.leaderstatsFolder.Wins.Value + 1
end
end
wait(3)
RemoveBall()
wait(7)
RemoveBall()
end
end)
GameStatus.StartGame.Event:Connect(function()
if TotalPlayers() == TotalPlrs then
local Players = script.Parent.Players
local QueuePlayers = script.Parent.QueuePlayers
GameStatus.GameReady.Value = false
AlreadyOn = false
local function CreateTeams()
Team1 = {} Team2 = {} CombinedTeams = {} PossessionTeam = "Team1" -- Resets Teams
for _, v in pairs(QueuePlayers:GetChildren()) do
if Players:FindFirstChild(v.Name).Value == nil then
Players:FindFirstChild(v.Name).Value = v.Value
v.Value = nil
end
end
for _, pad in pairs(QueuePlayers.Parent.Queue:GetChildren()) do
pad.Occupied.Value = false
end
end
CreateTeams() -- Creating Teams
NewGame()
table.insert(Team1, Players.Player1.Value) --Creating Team1
table.insert(Team2, Players.Player2.Value) --Creating Team2
table.insert(CombinedTeams, Players.Player1.Value) table.insert(CombinedTeams, Players.Player2.Value)
GameEvent:Fire("Team1Ball")
GameEvent:Fire("ScoreboardVisibility")
for _, plr in pairs (CombinedTeams) do
if plr.PlayerGui:FindFirstChild("HopOff") then
plr.PlayerGui:FindFirstChild("HopOff"):Destroy()
end
end
for _, v in pairs (script.Parent.Queue:GetChildren()) do
if v.BrickColor ~= BrickColor.new("Electric blue") then
v.Indicator.Enabled = false
end
end
end
end)
--Player Leaving Handle
game.Players.PlayerRemoving:Connect(function(plr)
for i, p in pairs(CombinedTeams) do
if p == plr then
table.remove(CombinedTeams, i)
end
end
for i, p in pairs(Team1) do
if p == plr then
table.remove(Team1, i)
end
end
for i, p in pairs(Team2) do
if p == plr then
table.remove(Team2, i)
end
end
for i, p in pairs(script.Parent.Players:GetChildren()) do
if p.Value == plr then
p.Value = nil
end
end
local function NumberOfPlayers()
local count = 0
for i, p in pairs(script.Parent.Players:GetChildren()) do
if p.Value ~= nil then
count = count + 1
end
end
return count
end
local function Team1Check()
local count = 0
for i, p in pairs (Team1) do
count = count + 1
end
return count
end
local function Team2Check()
local count = 0
for i, p in pairs (Team2) do
count = count + 1
end
return count
end
if Team1Check() ==0 and Team2Check() ~= 0 and GameStatus.GameReady.Value == false then
for _, plr in pairs (Team2) do
if game.Players:FindFirstChild(plr.Name) then
print("Awarding win.")
local Char = plr.Character
Char.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team1Spawn.Position)
plr.leaderstatsFolder.Wins.Value = plr.leaderstatsFolder.Wins.Value + 1
end
end
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
GameEvent:Fire("ScoreboardVisibility")
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
RemoveBall()
WalkSpeed()
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
end
end
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Parent = hpf.Value.PlayerGui
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.TeamPad.Value = queuepad
end
end
elseif Team2Check() ==0 and Team1Check() ~= 0 and GameStatus.GameReady.Value == false then
for _, plr in pairs (Team1) do
if game.Players:FindFirstChild(plr.Name) then
print("Awarding win.")
local Char = plr.Character
Char.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team1Spawn.Position)
plr.leaderstatsFolder.Wins.Value = plr.leaderstatsFolder.Wins.Value + 1
end
end
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
GameEvent:Fire("ScoreboardVisibility")
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
RemoveBall()
WalkSpeed()
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
end
end
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.Parent = hpf.Value.PlayerGui
HopOff.TeamPad.Value = queuepad
end
end
elseif Team1Check() == 0 and Team2Check() == 0 and GameStatus.GameReady.Value == false then
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
GameEvent:Fire("ScoreboardVisibility")
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
RemoveBall()
WalkSpeed()
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
end
end
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Parent = hpf.Value.PlayerGui
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.TeamPad.Value = queuepad
end
end
elseif GameStatus.GameReady.Value == true then
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
print("Enabled")
end
end
end
end)
function NewGame()
for _, plr in pairs (script.Parent.Players:GetChildren()) do
if plr.Value ~= nil then
local Char = game.Workspace:FindFirstChild(plr.Value.Name)
Char.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if Char.Humanoid.Health <=0 then
if plr.Value ~= nil then
plr.Value.leaderstatsFolder.Losses.Value = plr.Value.leaderstatsFolder.Losses.Value + 1
end
warn("Character Reset While in-game")
--Removing Team
for i, remove in pairs (Team1) do
if remove.Name == Char.Name then
table.remove(Team1, i)
print("Char Died")
end
end
for i, remove in pairs (Team2) do
if remove.Name == Char.Name then
table.remove(Team2, i)
print("Char Died")
end
end
for i, remove in pairs (CombinedTeams) do
if remove.Name == Char.Name then
table.remove(CombinedTeams, i)
print("Char Died")
end
end
plr.Value = nil
local function Team1Check()
local count = 0
for i, p in pairs (Team1) do
count = count + 1
end
return count
end
local function Team2Check()
local count = 0
for i, p in pairs (Team2) do
count = count + 1
end
return count
end
if Team1Check() ==0 and Team2Check() ~= 0 and GameStatus.GameReady.Value == false then
for _, plr in pairs (Team2) do
if game.Players:FindFirstChild(plr.Name) then
print("Awarding win.")
local Char = plr.Character
Char.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team1Spawn.Position)
plr.leaderstatsFolder.Wins.Value = plr.leaderstatsFolder.Wins.Value + 1
end
end
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
GameEvent:Fire("ScoreboardVisibility")
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
RemoveBall()
WalkSpeed()
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
end
end
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Parent = hpf.Value.PlayerGui
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.TeamPad.Value = queuepad
end
end
elseif Team2Check() ==0 and Team1Check() ~= 0 and GameStatus.GameReady.Value == false then
for _, plr in pairs (Team1) do
if game.Players:FindFirstChild(plr.Name) then
print("Awarding win.")
local Char = plr.Character
Char.HumanoidRootPart.CFrame = CFrame.new(script.Parent.TeamSpawns.Team1Spawn.Position)
plr.leaderstatsFolder.Wins.Value = plr.leaderstatsFolder.Wins.Value + 1
end
end
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
GameEvent:Fire("ScoreboardVisibility")
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
RemoveBall()
WalkSpeed()
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
end
end
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Parent = hpf.Value.PlayerGui
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
HopOff.TeamPad.Value = queuepad
end
end
elseif Team2Check() == 0 and Team1Check() == 0 and GameStatus.GameReady.Value == false then
GameStatus.Team1Score.Value = 0
GameStatus.Team2Score.Value = 0
GameEvent:Fire("UpdateScores")
GameEvent:Fire("ScoreboardVisibility")
GameStatus.ShotClock:FindFirstChild("On").Value = false
GameStatus.GameReady.Value = true
RemoveBall()
WalkSpeed()
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
end
end
for _, hpf in pairs (script.Parent.Players:GetChildren()) do
if hpf.Value ~= nil then
local queuepad = script.Parent.Queue:FindFirstChild(hpf.Name)
local HopOff = script.HopOff:Clone()
HopOff.Parent = hpf.Value.PlayerGui
HopOff.TeamPad.Value = queuepad
HopOff.Frame.ImageLabel.TextButton.Script.Disabled = false
end
end
elseif GameStatus.GameReady.Value == true then
for _, v in pairs (script.Parent.Players:GetChildren()) do
if v.Value == nil then
local findPlate = script.Parent.Queue:FindFirstChild(v.Name)
findPlate.Indicator.Enabled = true
print("Enabled")
end
end
end
end
end)
end
end
end