Why is there this error?

Hello, I am getting this error:

17:34:17.940 ServerScriptService.Game:43: Expected identifier when parsing function name, got ‘(’ - Studio - Game:43

The code there is:

	for i, v in pairs(matchPlayers) do
		v.Character:MoveTo(Vector3.new(math.random(-30, 30), 30, math.random(-30, 30))
	end

	repeat function()

Somebody please help

1 Like

I believe you need to add another End bracket at the end of the 2nd line

3 Likes

This looks really bad. Why do you need to create an anonymous function inside of a loop?

1 Like
for i, v in pairs(matchPlayers) do
	v.Character:MoveTo(Vector3.new(math.random(-30, 30), 30, math.random(-30, 30)))
end

Fixed

Im making a fight game and I thought that’d be the easiest way to do last man standing

well at the repeat function(), () has an error still. It’s Game.43

Then, show full code please.
()

K’

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 ()

Oh, I thought for repeats you could just do function() alone. Naming it fixed it.

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.

Sorry, I’m new to repeats. Also, V is a player. I’m removing the player from the table.

1 Like

Yes, but PlayerRemoving doesn’t work on a player. PlayerRemoving is a function of game.Players which detects when ANY player leaves the game.