Expected identifier when parsing expression, got ')'

I’m making a building system and I have everything done, but now it’s giving me an error saying:
Expected identifier when parsing expression, got ‘)’ - Studio - EditScript:103

local mouse = game.Players.LocalPlayer:GetMouse()
local hold = false
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("BuildPart")
local guiclicked = false
local clickDB = false
script.Parent.MouseButton1Click:Connect(function()
	if guiclicked == true then
		workspace.editMode:ClearAllChildren()
		guiclicked = false
		return
	end
	guiclicked = true
	local selectionPart = game.ReplicatedStorage.items.BasePart:Clone()
	selectionPart.Transparency = .5
	selectionPart.CanCollide = false
	local clicker = Instance.new("ClickDetector")
	clicker.CursorIcon = "rbxassetid://7545920160"
	clicker.MaxActivationDistance = 99999999
	selectionPart.Parent = workspace.editMode
	clicker.Parent = selectionPart
	local dragPos1
	local dragPos2
	local pLen
	local pWid
	while guiclicked == true do

		local position = mouse.Hit.p
		if position then
			selectionPart.Position = Vector3.new(math.ceil((position.X-3)/6)*6,2,math.ceil((position.Z-3)/6)*6)
		end

		UserInputService.InputBegan:Connect(function(inputObject)
			if hold == false then
				if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
					hold = true
					dragPos1 = Vector3.new(math.ceil((position.X-3)/6)*6,2,math.ceil((position.Z-3)/6)*6)
				end
			end
		end)  
		UserInputService.InputEnded:Connect(function(inputObject)
			if hold == true then
				if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
					hold = false

					dragPos2 = Vector3.new(math.ceil((position.X-3)/6)*6,2,math.ceil((position.Z-3)/6)*6)
					local lowX = math.min(dragPos1.X,dragPos2.X)
					local lowZ = math.min(dragPos1.Z,dragPos2.Z)
					if dragPos1.X-lowX ~= 0 then
						pLen = (dragPos1.X-lowX)/6
					else if dragPos2.X-lowX ~= 0 then
						pLen = (dragPos2.X-lowX)/6
					else if dragPos1.X-lowX == 0 or dragPos2.X-lowX == 0 then
						pLen = 0
					end	
					if dragPos1.Z-lowZ ~= 0 then
						pWid = (dragPos1.Z-lowZ)/6
					else if dragPos2.Z-lowZ ~= 0 then
						pWid = (dragPos2.Z-lowZ)/6
					else if dragPos1.Z-lowZ == 0 or dragPos2.Z-lowZ == 0 then
						pWid = 0
					end

					if dragPos1.X == lowX then
						for i=0, pLen do
							if dragPos1.Z == lowZ then
								for i=0, pWid do
									dragPos1.Z += i*6
									selectionPart.Name = dragPos1.X/6 .."-"..dragPos1.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos1)
								end
							else if dragPos2.Z == lowZ then
								for i=0, pWid do
									dragPos1.Z += i*6
									selectionPart.Name = dragPos2.X/6 .."-"..dragPos2.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos2)
								end				
							end
							dragPos1.X += i*6
						end				
					else if dragPos2.X == lowX then
						for i=0, pLen do
							if dragPos1.Z == lowZ then
								for i=0, pWid do
									dragPos1.Z += i*6
									selectionPart.Name = dragPos2.X/6 .."-"..dragPos2.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos1)
								end			
							else if dragPos2.Z == lowZ then
								for i=0, pWid do
									dragPos2.Z += i*6
									selectionPart.Name = dragPos2.X/6 .."-"..dragPos2.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos2)
								end			
							end	
							dragPos2.X += i*6							
						end
					end
				end
			end
		end)
		--[[
		clicker.MouseClick:Connect(function()
			if clickDB == false then
				selectionPart.Name = selectionPart.Position.X/6 .."-"..selectionPart.Position.Z/6
				remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,selectionPart.Position)
				clickDB = true
				wait(0.01)
				clickDB = false
			end
		end)
		]]--
		wait(.01)
	end


end)
fixed code
local mouse = game.Players.LocalPlayer:GetMouse()
local hold = false
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("BuildPart")
local guiclicked = false
local clickDB = false
script.Parent.MouseButton1Click:Connect(function()
	if guiclicked == true then
		workspace.editMode:ClearAllChildren()
		guiclicked = false
		return
	end
	guiclicked = true
	local selectionPart = game.ReplicatedStorage.items.BasePart:Clone()
	selectionPart.Transparency = .5
	selectionPart.CanCollide = false
	local clicker = Instance.new("ClickDetector")
	clicker.CursorIcon = "rbxassetid://7545920160"
	clicker.MaxActivationDistance = 99999999
	selectionPart.Parent = workspace.editMode
	clicker.Parent = selectionPart
	local dragPos1
	local dragPos2
	local pLen
	local pWid
	while guiclicked == true do

		local position = mouse.Hit.p
		if position then
			selectionPart.Position = Vector3.new(math.ceil((position.X-3)/6)*6,2,math.ceil((position.Z-3)/6)*6)
		end

		UserInputService.InputBegan:Connect(function(inputObject)
			if hold == false then
				if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
					hold = true
					dragPos1 = Vector3.new(math.ceil((position.X-3)/6)*6,2,math.ceil((position.Z-3)/6)*6)
				end
			end
		end)  
		UserInputService.InputEnded:Connect(function(inputObject)
			if hold == true then
				if inputObject.UserInputType == Enum.UserInputType.MouseButton1 then
					hold = false

					dragPos2 = Vector3.new(math.ceil((position.X-3)/6)*6,2,math.ceil((position.Z-3)/6)*6)
					local lowX = math.min(dragPos1.X,dragPos2.X)
					local lowZ = math.min(dragPos1.Z,dragPos2.Z)
					if dragPos1.X-lowX ~= 0 then
						pLen = (dragPos1.X-lowX)/6
					elseif dragPos2.X-lowX ~= 0 then
						pLen = (dragPos2.X-lowX)/6
					elseif dragPos1.X-lowX == 0 or dragPos2.X-lowX == 0 then
						pLen = 0
					end	
					if dragPos1.Z-lowZ ~= 0 then
						pWid = (dragPos1.Z-lowZ)/6
					elseif dragPos2.Z-lowZ ~= 0 then
						pWid = (dragPos2.Z-lowZ)/6
					elseif dragPos1.Z-lowZ == 0 or dragPos2.Z-lowZ == 0 then
						pWid = 0
					end

                    if dragPos1.X == lowX then
                        for i=0, pLen do
							if dragPos1.Z == lowZ then
								for i=0, pWid do
									dragPos1.Z += i*6
									selectionPart.Name = dragPos1.X/6 .."-"..dragPos1.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos1)
								end
							elseif dragPos2.Z == lowZ then
								for i=0, pWid do
									dragPos1.Z += i*6
									selectionPart.Name = dragPos2.X/6 .."-"..dragPos2.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos2)
								end				
							end
							dragPos1.X += i*6
						end	
                    elseif dragPos2.X == lowX then
                        for i=0, pLen do
							if dragPos1.Z == lowZ then
								for i=0, pWid do
									dragPos1.Z += i*6
									selectionPart.Name = dragPos2.X/6 .."-"..dragPos2.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos1)
								end			
							elseif dragPos2.Z == lowZ then
								for i=0, pWid do
									dragPos2.Z += i*6
									selectionPart.Name = dragPos2.X/6 .."-"..dragPos2.Z/6
									remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,dragPos2)
								end			
							end	
							dragPos2.X += i*6							
						end
                    end
				end
			end
		end)
		--[[
		clicker.MouseClick:Connect(function()
			if clickDB == false then
				selectionPart.Name = selectionPart.Position.X/6 .."-"..selectionPart.Position.Z/6
				remoteEvent:FireServer(selectionPart.Name,selectionPart.Color,selectionPart.Position)
				clickDB = true
				wait(0.01)
				clickDB = false
			end
		end)
		]]--
		wait(.01)
	end
end)

There were a bunch of elseif statements that were improperly written

Your code:

if condition then 
else if other_condition then
end

When it should be:

if condition then
elseif other_condition then
end

I highly suggest that you learn how to debug your code and read the error messages and compiler messages, because there will be errors throughout the duration of your coding career and if 1 compiler error blocks your workflow you won’t get too far.

Here’s a good debugging video:

1 Like