Syntax Error: Expected identifier when parsing expression, got ')'

I have little to no experience in Lua scripting. However, I have decided to task myself with fixing this team changer. Before, the code did not feature the last few lines that have to deal with the “NJSP” team changer. I am looking at one error, and it is the parenthesis at the end of the code. The error that pops up is "Syntax Error: Expected identifier when parsing expression, got ‘)’. As someone who rarely scripts or attempts to fix a script, I am looking for help in fixing this code. Thank you.

-- Paste the tools inside the Team, and anyone who spawns with that TeamColor will get it
local ReplicatedStorage = game:GetService("ReplicatedStorage")


for _, Player in ipairs(game.Players:GetPlayers()) do
	Player.CharacterAdded:connect(function() onCharacterAdded(Player) end)
end

function onPlayerAdded(Player)
	Player.CharacterAdded:connect(function() onCharacterAdded(Player) end)
end
game.Players.PlayerAdded:connect(onPlayerAdded)

function onCharacterAdded(Player)
	for _, Team in ipairs(game.Teams:GetChildren()) do
		if Team.TeamColor == Player.TeamColor then
			for _, Object in ipairs(Team:GetChildren()) do
				Object:Clone().Parent = Player.Backpack
			end
			break
		end
	end
end


ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, team)
	if team == "SLPD" then
		if player:IsInGroup(13618064) then
			player.Team = game.Teams.SLPD
		end
	elseif team == "Civilian" then
		player.Team = game.Teams.Citizen
	
	elseif team == "SLFD" then 
		if player:IsInGroup(6559812) then
			player.Team = game.Teams.SLFD
			
	elseif team == "NJSP" then 
		if player:IsInGroup(6835675) then
			player.Team = game.Teams.NJSP
		end
	end
end)

If you have any suggestions or can help me in identifying this error, that would be appreciated.

1 Like
	if team == "SLPD" then
		if player:IsInGroup(13618064) then
			player.Team = game.Teams.SLPD
		end
	elseif team == "Civilian" then
		player.Team = game.Teams.Citizen
	elseif team == "SLFD" then 
		if player:IsInGroup(6559812) then
			player.Team = game.Teams.SLFD
		end
	elseif team == "NJSP" then 
		if player:IsInGroup(6835675) then
			player.Team = game.Teams.NJSP
		end
	end

There was no end to the group check in the “SLFD” team

3 Likes

Syntax errors are usually common, the way I look at it is how much total functions, if statements, and events you’re adding onto your overall script (Or what I personally call, Actions):

  • ipairs & pairs
  • Events onPlayerAdded/onCharacterAdded
  • if statements

Here’s how I usually look at it:

-- So far, we have 0 syntax errors
local function AddPlr(Plr) -- Action 1
    print(Plr)

-- Where do we end Action 1 exactly?
-- But we don't have an end here to end our "AddPlr" function, so it results in 1 syntax error & how do we fix it? We add an "end" to end our little function:

local function AddPlr(Plr) -- Action 1
    print(Plr)
end -- End Action 1

Sometimes you may also get something like nested functions/events/if statements:

local function AddPlr(Plr) -- Action 1
    if Plr.Name == "Jackscarlett" then -- Action 2
end  -- End Action 1

-- Where do we end Action 2 exactly?
-- Now we already fixed our 1 local function, but we got another syntax error within checking for the Player's Name, we can add another "end" after checking if the Player's Name is equal to "Jackscarlett"

local function AddPlr(Plr) -- Action 1
    if Plr.Name == "Jackscarlett" then -- Action 2
        print("My name!") -- Incase a Player that has joined called: Jackscarlett has joined the game
    end -- End Action 2
end -- End Action 1

Just think of a Beginning, and an End

If there’s a beginning, then where is the end?

-- Paste the tools inside the Team, and anyone who spawns with that TeamColor will get it
local ReplicatedStorage = game:GetService("ReplicatedStorage")


for _, Player in ipairs(game.Players:GetPlayers()) do
	Player.CharacterAdded:connect(function() onCharacterAdded(Player) end)
end

function onPlayerAdded(Player)
	Player.CharacterAdded:connect(function() onCharacterAdded(Player) end)
end

game.Players.PlayerAdded:connect(onPlayerAdded)

function onCharacterAdded(Player)
	for _, Team in ipairs(game.Teams:GetChildren()) do
		if Team.TeamColor == Player.TeamColor then
			for _, Object in ipairs(Team:GetChildren()) do
				Object:Clone().Parent = Player.Backpack
			end
			break
		end
	end
end


ReplicatedStorage.ChangeTeam.OnServerEvent:Connect(function(player, team)
	if team == "SLPD" then
		if player:IsInGroup(13618064) then
			player.Team = game.Teams.SLPD
		end
	elseif team == "Civilian" then
		player.Team = game.Teams.Citizen

	elseif team == "SLFD" then 
		if player:IsInGroup(6559812) then
			player.Team = game.Teams.SLFD

		elseif team == "NJSP" then 
			if player:IsInGroup(6835675) then
				player.Team = game.Teams.NJSP
			end
		end
	end
end)
1 Like

As someone who has probably touched a script under 100 times in their life, this was actually extremely helpful. I look up to your methods of educating, and I would like to thank you for taking time out of your day to type this up!

1 Like