RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"can you add a variable for the min amount of players"
Sure, here's the updated script with a minimum player count variable added: ```lua -- server script local players = game:GetService("Players") local roundTime = 60 -- 1 minute rounds local miniRoundTime = 10 -- 10 second mini rounds local playerStartPosRange = 100 -- players will start randomly within this range local minPlayers = 2 -- minimum number of players to start a round local playerStates = {} -- Dictionary to store the state of each player local ball = game.Workspace.Dodgeball local ballStartPos = ball.Position -- store the initial position of the ball local function resetRound() print("Resetting round...") for _, player in pairs(players:GetPlayers()) do playerStates[player.Name] = {HasBall = false, IsAlive = true} -- place players randomly on the map local randomX = math.random(-playerStartPosRange, playerStartPosRange) local randomZ = math.random(-playerStartPosRange, playerStartPosRange) player.Character.HumanoidRootPart.Position = Vector3.new(randomX, 0, randomZ) end -- reset the ball to its starting position ball.Position = ballStartPos print("Round reset.") end local function startRound() if #players:GetPlayers() < minPlayers then print("Not enough players to start a round.") return end print("Starting round...") local alivePlayers = players:GetPlayers() local ballHolder = alivePlayers[math.random(#alivePlayers)] playerStates[ballHolder.Name] = {HasBall = true, IsAlive = true} for i=roundTime, 0, -miniRoundTime do task.wait(miniRoundTime) if #alivePlayers == 1 then print(alivePlayers[1].Name .. " wins the round!") resetRound() break else -- If the ball holder still has the ball after the mini round, they are out if playerStates[ballHolder.Name].HasBall then print(ballHolder.Name .. " is out!") table.remove(alivePlayers, table.find(alivePlayers, ballHolder)) playerStates[ballHolder.Name].IsAlive = false -- Pass the ball to a new random player ballHolder = alivePlayers[math.random(#alivePlayers)] playerStates[ballHolder.Name] = {HasBall = true, IsAlive = true} end end end print("Round ended.") end while true do task.wait(5) -- Wait 5 seconds between rounds startRound() end ``` This script now checks if there are at least `minPlayers` in the game before starting a round. If not, it prints a message and waits until the next round to check again.