Help finding the cause of a syntax error (missing "End")

Hi could I please get some trying to find the cause of my error message:

  ServerScriptService.PickUpHandler:72: Expected 'end' (to close 'function' at line 29), got <eof>; did you forget to close 'do' at line 70?  -  Studio - PickUpHandler:72

I’ve been looking for the cause of it for an hour now and I just can’t find it, help would be appreciated.
feel free to paste it into a script in studio and debug it that way.
I believe the cause is within the function pickOrDrop(player, part)

wait(4)
-- Variables
local playerParts = {}
local collectionService = game:GetService("CollectionService")
local TAG_NAME = "PickUp"

-- Drop part
local function drop(player)
	
	playerParts[player] = nil
	print("Dropping")
	return
end

-- Pick up part
local function pickUp(player, part)
	--if not collectionService:HasTag(part, TAG_NAME) then return end
	
	for _, p in pairs (playerParts) do
		if p == part then return end
	end
	
	playerParts[player] = part
	print("Picking up")
	return
end

-- Decide wether to drop or pick up part
local function pickOrDrop(player, part)
	
	if playerParts[player] then
		drop(player)
	else if part and not playerParts[player] then 
		pickUp(player, part)
	else return end
end

-- Test functions by giving them random data
local names = {"Cody", "Liam", "Saequan", "Devon", "Joe"}
local objects = {"Vending machine", "Bench", "Seat", "Table", "Board"}
local nameArray = {}
local objectArray = {}

local function rngTable()
	local bufferNames = {}
	local bufferObjects = {}
	
	for i = 1, #names do
		bufferNames[i] = names[i]
		bufferObjects[i] = objects[i]
	end
	
	while (#bufferNames > 0)  do
		nameArray[#nameArray + 1] = table.remove(bufferNames, math.random(#bufferNames))
	end
	
	while (#bufferObjects > 0)  do
		objectArray[#objectArray + 1] = table.remove(bufferObjects, math.random(#bufferObjects))
	end
	
	return nameArray, objectArray
end

local namesArray, objectsArray = rngTable()

for i = 1, #namesArray do
	pickOrDrop(namesArray[i], objectsArray[i])
end

for i = 1, #objectsArray do
	pickOrDrop(namesArray[i], objectsArray[i])
end

Don’t use else if, use elseif instead

Thanks it works now. I haven’t really used else if before lol. :slight_smile:

1 Like