Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local Configuration = ReplicatedStorage.Configuration
- local Players = game:GetService("Players")
- local Teams = game:GetService("Teams")
- local ServerStorage = game:GetService("ServerStorage")
- local RunService = game:GetService("RunService")
- local Team1 = Teams:WaitForChild("Team1")
- local Team2 = Teams:WaitForChild("Team2")
- local Spectators = Teams:WaitForChild("Spectating")
- local team1PointsValue = ReplicatedStorage.Network:FindFirstChild("Team1Points")
- local team2PointsValue = ReplicatedStorage.Network:FindFirstChild("Team2Points")
- local timerValue = ReplicatedStorage.Network:FindFirstChild("Timer")
- local gameCurrent = ReplicatedStorage.Network:FindFirstChild("GameCurrent")
- local Scored = false
- local isGameStarted = false
- local connection
- local CurrenctQuarter
- local MaxQuarter = 4
- local IsBreakTime = false
- local yesballa = true
- local function startGame()
- if isGameStarted then
- return
- end
- for _,balls in pairs(game:GetService("Workspace"):GetDescendants()) do
- if balls.Name == "Ball" then
- balls:Destroy()
- end
- end
- local NewBall = Configuration.Models.Ball:Clone()
- NewBall.Parent = game:GetService("Workspace").Balls
- NewBall.Position = Vector3.new(-138.66, 3.688, 315.919)
- team1PointsValue.Value = 0
- team2PointsValue.Value = 0
- gameCurrent.Value = true
- -- Start timer
- local startTime = tick()
- local endTime = startTime + 3 -- Set timer for 1 minute
- CurrenctQuarter = 1
- local function updateTimer()
- if not isGameStarted and not IsBreakTime then
- return
- end
- local currentTime = tick()
- local remainingTime = endTime - currentTime
- local function addTime()
- remainingTime += 20
- end
- if remainingTime > 0 then
- timerValue.Value = remainingTime
- else
- -- timerValue.Value = 0
- end
- if remainingTime <= 0 and not IsBreakTime then
- if CurrenctQuarter > MaxQuarter then
- if team1PointsValue.Value > team2PointsValue.Value then
- for _, player in ipairs(Players:GetPlayers()) do
- if player.Team == game.Teams.Team1 then
- ReplicatedStorage.DatatstoreBindable:Fire(player)
- end
- end
- ReplicatedStorage.RemoteEvent:FireAllClients("Team1")
- elseif team2PointsValue.Value > team1PointsValue.Value then
- ReplicatedStorage.RemoteEvent:FireAllClients("Team2")
- for _, player in ipairs(Players:GetPlayers()) do
- if player.Team == game.Teams.Team2 then
- ReplicatedStorage.DatatstoreBindable:Fire(player)
- end
- end
- else
- ReplicatedStorage.RemoteEvent:FireAllClients("Draw")
- end
- connection:Disconnect()
- isGameStarted = false
- gameCurrent.Value = false
- Configuration.Eventos.System.StealBall:FireAllClients()
- local endTime = startTime + 60
- for _, ball in pairs(game:GetService("Workspace"):GetDescendants()) do
- if ball.Name == "ball" then
- ball:Destroy()
- end
- end
- local NewBall = Configuration.Models.Ball:Clone()
- NewBall.Parent = game:GetService("Workspace").Balls
- elseif CurrenctQuarter < MaxQuarter and not IsBreakTime then
- IsBreakTime = true
- task.wait(5)
- local endTime = startTime + 5
- IsBreakTime = false
- end
- end
- team1PointsValue.Changed:Connect(function()
- addTime()
- ReplicatedStorage.UISpecility:FireAllClients("AddedTime")
- end)
- team2PointsValue.Changed:Connect(function()
- addTime()
- ReplicatedStorage.UISpecility:FireAllClients("AddedTime")
- end)
- end
- local team1Folder = game:GetService("Workspace").Positions:FindFirstChild("Team1")
- local team2Folder = game:GetService("Workspace").Positions:FindFirstChild("Team2")
- local team1Players = {}
- local team2Players = {}
- for _, player in pairs(game:GetService("Players"):GetPlayers()) do
- if player.Team == game:GetService("Teams"):FindFirstChild("Team1") then
- table.insert(team1Players, player)
- elseif player.Team == game:GetService("Teams"):FindFirstChild("Team2") then
- table.insert(team2Players, player)
- end
- end
- local function shuffle(list)
- for i = #list, 2, -1 do
- local j = math.random(i)
- list[i], list[j] = list[j], list[i]
- end
- end
- shuffle(team1Players)
- shuffle(team2Players)
- for i = 1, math.min(#team1Players, 5) do
- local player = team1Players[i]
- local position = team1Folder[i]
- local targetPosition = position.Position + position.CFrame.LookVector
- local newPosition = CFrame.lookAt(position.Position, targetPosition)
- player.Character:SetPrimaryPartCFrame(newPosition)
- end
- for i = 1, math.min(#team2Players, 5) do
- local player = team2Players[i]
- local position = team2Folder[i]
- local targetPosition = position.Position + position.CFrame.LookVector
- local newPosition = CFrame.lookAt(position.Position, targetPosition)
- player.Character:SetPrimaryPartCFrame(newPosition)
- end
- local function scored()
- for i = 1, math.min(#team1Players, 5) do
- local player = team1Players[i]
- local position = team1Folder[i]
- local targetPosition = position.Position + position.CFrame.LookVector
- local newPosition = CFrame.lookAt(position.Position, targetPosition)
- player.Character:SetPrimaryPartCFrame(newPosition)
- end
- for i = 1, math.min(#team2Players, 5) do
- local player = team2Players[i]
- local position = team2Folder[i]
- local targetPosition = position.Position + position.CFrame.LookVector
- local newPosition = CFrame.lookAt(position.Position, targetPosition)
- player.Character:SetPrimaryPartCFrame(newPosition)
- end
- end
- ReplicatedStorage.Simon.Event:Connect(function()
- end)
- local function onBallCollision(part,player,raycast)
- if part == "ScorePart" and not Scored then
- Scored = true
- yesballa = false
- ReplicatedStorage.Configuration.Eventos.System.StealBall:FireAllClients()
- game:GetService("Workspace"):FindFirstChild("Balls").Ball:Destroy()
- Configuration.Eventos.System.StealBall:FireAllClients()
- if raycast:GetAttribute("Team") == "Team1" then
- team2PointsValue.Value = team2PointsValue.Value + 1
- elseif raycast:GetAttribute("Team") == "Team2" then
- team1PointsValue.Value = team1PointsValue.Value + 1
- end
- task.wait(10)
- scored()
- task.wait(1)
- local NewBall = Configuration.Models.Ball:Clone()
- NewBall.Parent = game:GetService("Workspace").Balls
- NewBall.AssemblyLinearVelocity = Vector3.new(0,0,0)
- NewBall.Position = Vector3.new(-138.66, 3.688, 315.919)
- yesballa = true
- task.wait(2)
- Scored = false
- elseif part == "OutOfBounds" then
- local hitPosition = raycast.Position
- ReplicatedStorage.Configuration.Eventos.System.StealBall:FireAllClients()
- local OOBPosParts = game:GetService("Workspace"):GetDescendants() -- Get all descendants of workspace
- local nearestPart = nil
- local minDistance = math.huge -- Set initial minimum distance to a large value
- local nearestPlayer = nil
- for _, part in ipairs(OOBPosParts) do
- if part:IsA("BasePart") and part.Parent.Name == "OOBPos" then
- local distance = (hitPosition - part.Position).Magnitude
- if distance < minDistance then
- minDistance = distance
- nearestPart = part
- end
- end
- end
- if nearestPart then
- if player.Team.Name == "Team1" or player.Team == Teams["Team1"] then
- for _, team2Player in ipairs(game.Players:GetPlayers()) do
- if team2Player.Team.Name == "Team2" then
- if not nearestPlayer or (team2Player.Character.HumanoidRootPart.Position - nearestPart.Position).Magnitude < minDistance then
- nearestPlayer = team2Player
- end
- end
- end
- elseif player.Team.Name == "Team2" or player.Team == Teams["Team2"] then
- for _, team1Player in ipairs(game.Players:GetPlayers()) do
- if team1Player.Team.Name == "Team1" then
- if not nearestPlayer or (team1Player.Character.HumanoidRootPart.Position - nearestPart.Position).Magnitude < minDistance then
- nearestPlayer = team1Player
- end
- end
- end
- end
- if nearestPlayer then
- game:GetService("Workspace").Balls.Ball:Destroy()
- local Newoutbaon = Configuration.Models.Ball:Clone()
- Newoutbaon.Parent = game:GetService("Workspace").Balls
- nearestPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(nearestPart.Position)
- task.wait(0.1)
- Newoutbaon.CFrame = CFrame.new(nearestPlayer.Character.HumanoidRootPart.CFrame.Position)
- end
- end
- end
- end
- ReplicatedStorage.EventB.Event:Connect(function(part, player,raycast)
- onBallCollision(part, player, raycast)
- end)
- connection = RunService.Heartbeat:Connect(function()
- updateTimer()
- if not game:GetService("Workspace"):FindFirstChild("Balls"):FindFirstChild("Ball") and yesballa then
- yesballa = false
- scored()
- task.wait(1)
- if game:GetService("Workspace").Balls:FindFirstChild("Ball") then
- game:GetService("Workspace").Balls:FindFirstChild("Ball"):Destroy()
- end
- repeat wait() until not game:GetService("Workspace").Balls:FindFirstChild("Ball")
- local NewBall = Configuration.Models.Ball:Clone()
- NewBall.Parent = game:GetService("Workspace").Balls
- NewBall.AssemblyLinearVelocity = Vector3.new(0,0,0)
- NewBall.Position = Vector3.new(-138.66, 3.688, 315.919)
- wait(2)
- yesballa = true
- end
- end)
- local function endGame()
- gameCurrent.Value = false
- isGameStarted = false
- connection:Disconnect()
- timerValue.Value = 0
- end
- updateTimer()
- isGameStarted = true
- return endGame
- end
- Players.PlayerAdded:Connect(function(Player)
- local Character = Player.Character or Player.CharacterAdded:Wait()
- local function removeBall()
- for _, v in ipairs(game:GetService("Workspace"):GetDescendants()) do
- if v.Name == "ball" and v:GetAttribute("Player") == Player.Name then
- v:Destroy()
- if v:FindFirstChild("Weld") then
- v.Weld:Destroy()
- end
- end
- end
- end
- local maxPlayersPerTeam = 5
- local function countPlayersInTeam(team)
- local count = 0
- for _, player in pairs(game:GetService("Players"):GetPlayers()) do
- if player.Team == team then
- count = count + 1
- end
- end
- return count
- end
- Player.Chatted:Connect(function(Message)
- if Message == "Start" and not gameCurrent.Value then
- local team1Count = countPlayersInTeam(Team1)
- local team2Count = countPlayersInTeam(Team2)
- startGame()
- if team1Count >= 1 and team2Count >= 1 and Player.Team ~= Spectators then
- startGame()
- removeBall()
- else
- print("Cannot start the game. Make sure there is at least one player on each team and you are not in the spectators team.")
- end
- elseif Message == "Team1" then
- removeBall()
- if countPlayersInTeam(Team1) < maxPlayersPerTeam then
- Player.Team = Team1
- Player.Character:SetPrimaryPartCFrame(CFrame.new(game:GetService("Workspace").Team1.Position))
- else
- print("Team1 is full. Choose another team or spectate.")
- end
- elseif Message == "Team2" then
- removeBall()
- if countPlayersInTeam(Team2) < maxPlayersPerTeam then
- Player.Team = Team2
- Player.Character:SetPrimaryPartCFrame(CFrame.new(game:GetService("Workspace").Team2.Position))
- else
- print("Team2 is full. Choose another team or spectate.")
- end
- elseif Message == "Spectate" then
- removeBall()
- Player.Team = Spectators
- Player.Character:SetPrimaryPartCFrame(CFrame.new(game:GetService("Workspace").Spectating.Position))
- end
- end)
- end)
Advertisement
Add Comment
Please, Sign In to add comment