wait(1)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local function restart()
script.Disabled = true
wait()
script.Disabled = false
end
local maps = {
ReplicatedStorage.ForestMap,
ReplicatedStorage.WorshipMap,
ReplicatedStorage.NeonMap
}
local gameStatus = ReplicatedStorage.gameStatus
while true do
--Waiting
gameStatus.Value = "Waiting for Players"
repeat wait() until Players.NumPlayers > 1
--Intermission
gameStatus.Value = "Intermission, Time Left: "
local timeLeft = 15
for i = 1, timeLeft do
gameStatus.Value = ("Intermission, Time Left: " .. timeLeft)
wait(1)
timeLeft -= 1
end
--StartingGame
local chosenMap = maps[math.random(1, #maps)]
chosenMap.Parent = game.Workspace
local matchPlayers = {}
for i, v in pairs(Players:GetPlayers()) do
table.insert(matchPlayers, v)
end
gameStatus.Value = "Game In Progress"
for i, v in pairs(matchPlayers) do
v.Character:MoveTo(Vector3.new(math.random(-30, 30), 30, math.random(-30, 30)))
end
--Game
repeat function()
for i, v in pairs(matchPlayers) do
v.PlayerRemoving:Connect(function()
table.remove(matchPlayers, v)
end)
end
end
until #matchPlayers == 1
--WinnerRewardAndGameEnd
matchPlayers[1].leaderstats.Wins += 1
matchPlayers[1].Character.Humanoid.Health = 0
chosenMap.Parent = ReplicatedStorage
restart()
end
for i, v in pairs(matchPlayers) do
v.Character:MoveTo(Vector3.new(math.random(-30, 30), 30, math.random(-30, 30))
end
repeat function()
Why are you saying repeat function()?
if you want to move all players which I assume you do simply call the for loop by putting it in a function like this:
function MovePlayers()
for i, v in pairs(matchPlayers) do
v.Character:MoveTo(Vector3.new(math.random(-30, 30), 30, math.random(-30, 30))
end
end
MovePlayers()
Also the error is because you didn’t name the function, studio expected a name after function but you put ()
Remove the function part of the repeat it does nothing
repeat -- Removed function
for i, v in pairs(matchPlayers) do
v.PlayerRemoving:Connect(function()
table.remove(matchPlayers, v)
end)
-- Removed end
end
until #matchPlayers == 1
You don’t even need the function inside of the repeat. Just have the repeat function. Also, it would be better to have it like this:
local connection = game.Players.PlayerRemoving:Connect(function(plr)
if table.find(matchPlayers, plr) then
table.remove(matchPlayers, table.find(matchPlayers, plr))
end
end)
repeat task.wait() until #matchPlayers == 1
connection:Disconnect()
The table.remove you had wouldn’t work as table.remove() needs the index of the item you are trying to remove.