Guest User

Handler

a guest
Jul 4th, 2023
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.37 KB | None | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local Configuration = ReplicatedStorage.Configuration
  3.  
  4. local Players = game:GetService("Players")
  5. local Teams = game:GetService("Teams")
  6.  
  7. local ServerStorage = game:GetService("ServerStorage")
  8. local RunService = game:GetService("RunService")
  9.  
  10. local Team1 = Teams:WaitForChild("Team1")
  11. local Team2 = Teams:WaitForChild("Team2")
  12. local Spectators = Teams:WaitForChild("Spectating")
  13.  
  14. local team1PointsValue = ReplicatedStorage.Network:FindFirstChild("Team1Points")
  15. local team2PointsValue = ReplicatedStorage.Network:FindFirstChild("Team2Points")
  16. local timerValue = ReplicatedStorage.Network:FindFirstChild("Timer")
  17. local gameCurrent = ReplicatedStorage.Network:FindFirstChild("GameCurrent")
  18.  
  19. local Scored = false
  20.  
  21. local isGameStarted = false
  22. local connection
  23.  
  24. local CurrenctQuarter
  25. local MaxQuarter = 4
  26. local IsBreakTime = false
  27.  
  28. local yesballa = true
  29.  
  30. local function startGame()
  31. if isGameStarted then
  32. return
  33. end
  34.  
  35. for _,balls in pairs(game:GetService("Workspace"):GetDescendants()) do
  36. if balls.Name == "Ball" then
  37. balls:Destroy()
  38. end
  39. end
  40.  
  41. local NewBall = Configuration.Models.Ball:Clone()
  42. NewBall.Parent = game:GetService("Workspace").Balls
  43. NewBall.Position = Vector3.new(-138.66, 3.688, 315.919)
  44.  
  45.  
  46. team1PointsValue.Value = 0
  47. team2PointsValue.Value = 0
  48. gameCurrent.Value = true
  49.  
  50. -- Start timer
  51. local startTime = tick()
  52. local endTime = startTime + 3 -- Set timer for 1 minute
  53. CurrenctQuarter = 1
  54. local function updateTimer()
  55. if not isGameStarted and not IsBreakTime then
  56. return
  57. end
  58.  
  59.  
  60. local currentTime = tick()
  61. local remainingTime = endTime - currentTime
  62.  
  63. local function addTime()
  64. remainingTime += 20
  65. end
  66.  
  67.  
  68. if remainingTime > 0 then
  69. timerValue.Value = remainingTime
  70. else
  71. -- timerValue.Value = 0
  72. end
  73.  
  74. if remainingTime <= 0 and not IsBreakTime then
  75. if CurrenctQuarter > MaxQuarter then
  76. if team1PointsValue.Value > team2PointsValue.Value then
  77. for _, player in ipairs(Players:GetPlayers()) do
  78. if player.Team == game.Teams.Team1 then
  79. ReplicatedStorage.DatatstoreBindable:Fire(player)
  80. end
  81. end
  82. ReplicatedStorage.RemoteEvent:FireAllClients("Team1")
  83. elseif team2PointsValue.Value > team1PointsValue.Value then
  84. ReplicatedStorage.RemoteEvent:FireAllClients("Team2")
  85. for _, player in ipairs(Players:GetPlayers()) do
  86. if player.Team == game.Teams.Team2 then
  87. ReplicatedStorage.DatatstoreBindable:Fire(player)
  88. end
  89. end
  90. else
  91. ReplicatedStorage.RemoteEvent:FireAllClients("Draw")
  92. end
  93. connection:Disconnect()
  94. isGameStarted = false
  95. gameCurrent.Value = false
  96. Configuration.Eventos.System.StealBall:FireAllClients()
  97. local endTime = startTime + 60
  98. for _, ball in pairs(game:GetService("Workspace"):GetDescendants()) do
  99. if ball.Name == "ball" then
  100. ball:Destroy()
  101. end
  102. end
  103. local NewBall = Configuration.Models.Ball:Clone()
  104. NewBall.Parent = game:GetService("Workspace").Balls
  105. elseif CurrenctQuarter < MaxQuarter and not IsBreakTime then
  106.  
  107. IsBreakTime = true
  108. task.wait(5)
  109. local endTime = startTime + 5
  110. IsBreakTime = false
  111. end
  112. end
  113.  
  114. team1PointsValue.Changed:Connect(function()
  115. addTime()
  116. ReplicatedStorage.UISpecility:FireAllClients("AddedTime")
  117. end)
  118. team2PointsValue.Changed:Connect(function()
  119. addTime()
  120. ReplicatedStorage.UISpecility:FireAllClients("AddedTime")
  121. end)
  122.  
  123. end
  124.  
  125.  
  126. local team1Folder = game:GetService("Workspace").Positions:FindFirstChild("Team1")
  127. local team2Folder = game:GetService("Workspace").Positions:FindFirstChild("Team2")
  128.  
  129. local team1Players = {}
  130. local team2Players = {}
  131.  
  132. for _, player in pairs(game:GetService("Players"):GetPlayers()) do
  133. if player.Team == game:GetService("Teams"):FindFirstChild("Team1") then
  134. table.insert(team1Players, player)
  135. elseif player.Team == game:GetService("Teams"):FindFirstChild("Team2") then
  136. table.insert(team2Players, player)
  137. end
  138. end
  139.  
  140. local function shuffle(list)
  141. for i = #list, 2, -1 do
  142. local j = math.random(i)
  143. list[i], list[j] = list[j], list[i]
  144. end
  145. end
  146.  
  147. shuffle(team1Players)
  148. shuffle(team2Players)
  149.  
  150. for i = 1, math.min(#team1Players, 5) do
  151. local player = team1Players[i]
  152. local position = team1Folder[i]
  153.  
  154. local targetPosition = position.Position + position.CFrame.LookVector
  155. local newPosition = CFrame.lookAt(position.Position, targetPosition)
  156. player.Character:SetPrimaryPartCFrame(newPosition)
  157. end
  158.  
  159. for i = 1, math.min(#team2Players, 5) do
  160. local player = team2Players[i]
  161. local position = team2Folder[i]
  162.  
  163. local targetPosition = position.Position + position.CFrame.LookVector
  164. local newPosition = CFrame.lookAt(position.Position, targetPosition)
  165. player.Character:SetPrimaryPartCFrame(newPosition)
  166. end
  167.  
  168.  
  169.  
  170. local function scored()
  171. for i = 1, math.min(#team1Players, 5) do
  172. local player = team1Players[i]
  173. local position = team1Folder[i]
  174.  
  175. local targetPosition = position.Position + position.CFrame.LookVector
  176. local newPosition = CFrame.lookAt(position.Position, targetPosition)
  177. player.Character:SetPrimaryPartCFrame(newPosition)
  178. end
  179.  
  180. for i = 1, math.min(#team2Players, 5) do
  181. local player = team2Players[i]
  182. local position = team2Folder[i]
  183.  
  184. local targetPosition = position.Position + position.CFrame.LookVector
  185. local newPosition = CFrame.lookAt(position.Position, targetPosition)
  186. player.Character:SetPrimaryPartCFrame(newPosition)
  187. end
  188. end
  189.  
  190. ReplicatedStorage.Simon.Event:Connect(function()
  191.  
  192. end)
  193.  
  194. local function onBallCollision(part,player,raycast)
  195. if part == "ScorePart" and not Scored then
  196. Scored = true
  197. yesballa = false
  198. ReplicatedStorage.Configuration.Eventos.System.StealBall:FireAllClients()
  199. game:GetService("Workspace"):FindFirstChild("Balls").Ball:Destroy()
  200. Configuration.Eventos.System.StealBall:FireAllClients()
  201. if raycast:GetAttribute("Team") == "Team1" then
  202. team2PointsValue.Value = team2PointsValue.Value + 1
  203. elseif raycast:GetAttribute("Team") == "Team2" then
  204. team1PointsValue.Value = team1PointsValue.Value + 1
  205. end
  206.  
  207. task.wait(10)
  208. scored()
  209. task.wait(1)
  210. local NewBall = Configuration.Models.Ball:Clone()
  211. NewBall.Parent = game:GetService("Workspace").Balls
  212. NewBall.AssemblyLinearVelocity = Vector3.new(0,0,0)
  213. NewBall.Position = Vector3.new(-138.66, 3.688, 315.919)
  214. yesballa = true
  215. task.wait(2)
  216. Scored = false
  217.  
  218. elseif part == "OutOfBounds" then
  219. local hitPosition = raycast.Position
  220. ReplicatedStorage.Configuration.Eventos.System.StealBall:FireAllClients()
  221. local OOBPosParts = game:GetService("Workspace"):GetDescendants() -- Get all descendants of workspace
  222. local nearestPart = nil
  223. local minDistance = math.huge -- Set initial minimum distance to a large value
  224. local nearestPlayer = nil
  225.  
  226. for _, part in ipairs(OOBPosParts) do
  227. if part:IsA("BasePart") and part.Parent.Name == "OOBPos" then
  228. local distance = (hitPosition - part.Position).Magnitude
  229. if distance < minDistance then
  230. minDistance = distance
  231. nearestPart = part
  232. end
  233. end
  234. end
  235.  
  236. if nearestPart then
  237. if player.Team.Name == "Team1" or player.Team == Teams["Team1"] then
  238. for _, team2Player in ipairs(game.Players:GetPlayers()) do
  239. if team2Player.Team.Name == "Team2" then
  240. if not nearestPlayer or (team2Player.Character.HumanoidRootPart.Position - nearestPart.Position).Magnitude < minDistance then
  241. nearestPlayer = team2Player
  242. end
  243. end
  244. end
  245. elseif player.Team.Name == "Team2" or player.Team == Teams["Team2"] then
  246. for _, team1Player in ipairs(game.Players:GetPlayers()) do
  247. if team1Player.Team.Name == "Team1" then
  248. if not nearestPlayer or (team1Player.Character.HumanoidRootPart.Position - nearestPart.Position).Magnitude < minDistance then
  249. nearestPlayer = team1Player
  250. end
  251. end
  252. end
  253. end
  254.  
  255. if nearestPlayer then
  256. game:GetService("Workspace").Balls.Ball:Destroy()
  257. local Newoutbaon = Configuration.Models.Ball:Clone()
  258. Newoutbaon.Parent = game:GetService("Workspace").Balls
  259. nearestPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(nearestPart.Position)
  260. task.wait(0.1)
  261. Newoutbaon.CFrame = CFrame.new(nearestPlayer.Character.HumanoidRootPart.CFrame.Position)
  262. end
  263. end
  264. end
  265. end
  266.  
  267. ReplicatedStorage.EventB.Event:Connect(function(part, player,raycast)
  268. onBallCollision(part, player, raycast)
  269. end)
  270. connection = RunService.Heartbeat:Connect(function()
  271. updateTimer()
  272.  
  273. if not game:GetService("Workspace"):FindFirstChild("Balls"):FindFirstChild("Ball") and yesballa then
  274. yesballa = false
  275. scored()
  276. task.wait(1)
  277. if game:GetService("Workspace").Balls:FindFirstChild("Ball") then
  278. game:GetService("Workspace").Balls:FindFirstChild("Ball"):Destroy()
  279. end
  280. repeat wait() until not game:GetService("Workspace").Balls:FindFirstChild("Ball")
  281. local NewBall = Configuration.Models.Ball:Clone()
  282. NewBall.Parent = game:GetService("Workspace").Balls
  283. NewBall.AssemblyLinearVelocity = Vector3.new(0,0,0)
  284. NewBall.Position = Vector3.new(-138.66, 3.688, 315.919)
  285. wait(2)
  286. yesballa = true
  287. end
  288. end)
  289.  
  290. local function endGame()
  291. gameCurrent.Value = false
  292. isGameStarted = false
  293. connection:Disconnect()
  294. timerValue.Value = 0
  295. end
  296.  
  297. updateTimer()
  298. isGameStarted = true
  299.  
  300. return endGame
  301. end
  302.  
  303.  
  304.  
  305.  
  306.  
  307. Players.PlayerAdded:Connect(function(Player)
  308. local Character = Player.Character or Player.CharacterAdded:Wait()
  309.  
  310. local function removeBall()
  311. for _, v in ipairs(game:GetService("Workspace"):GetDescendants()) do
  312. if v.Name == "ball" and v:GetAttribute("Player") == Player.Name then
  313. v:Destroy()
  314. if v:FindFirstChild("Weld") then
  315. v.Weld:Destroy()
  316. end
  317. end
  318. end
  319. end
  320.  
  321. local maxPlayersPerTeam = 5
  322.  
  323. local function countPlayersInTeam(team)
  324. local count = 0
  325. for _, player in pairs(game:GetService("Players"):GetPlayers()) do
  326. if player.Team == team then
  327. count = count + 1
  328. end
  329. end
  330. return count
  331. end
  332.  
  333. Player.Chatted:Connect(function(Message)
  334. if Message == "Start" and not gameCurrent.Value then
  335. local team1Count = countPlayersInTeam(Team1)
  336. local team2Count = countPlayersInTeam(Team2)
  337. startGame()
  338.  
  339. if team1Count >= 1 and team2Count >= 1 and Player.Team ~= Spectators then
  340. startGame()
  341. removeBall()
  342. else
  343. print("Cannot start the game. Make sure there is at least one player on each team and you are not in the spectators team.")
  344. end
  345. elseif Message == "Team1" then
  346. removeBall()
  347. if countPlayersInTeam(Team1) < maxPlayersPerTeam then
  348. Player.Team = Team1
  349. Player.Character:SetPrimaryPartCFrame(CFrame.new(game:GetService("Workspace").Team1.Position))
  350. else
  351. print("Team1 is full. Choose another team or spectate.")
  352. end
  353. elseif Message == "Team2" then
  354. removeBall()
  355. if countPlayersInTeam(Team2) < maxPlayersPerTeam then
  356. Player.Team = Team2
  357. Player.Character:SetPrimaryPartCFrame(CFrame.new(game:GetService("Workspace").Team2.Position))
  358. else
  359. print("Team2 is full. Choose another team or spectate.")
  360. end
  361. elseif Message == "Spectate" then
  362. removeBall()
  363. Player.Team = Spectators
  364. Player.Character:SetPrimaryPartCFrame(CFrame.new(game:GetService("Workspace").Spectating.Position))
  365. end
  366. end)
  367.  
  368.  
  369. end)
  370.  
Advertisement
Add Comment
Please, Sign In to add comment