Script Issue for 'end' and ")"

I just added some more code to a script and it is throwing the following code:
[Script:81: Expected ‘)’ (to close ‘(’ at line 41), got ‘end’]

I’m confused as how to tell what I need to fix. Here is the code:

local vehiclefunc = game.ReplicatedStorage.Vehicle
Cloned2 = game.ReplicatedStorage["Vehicle"]:clone()

game.ServerStorage["Vehicle"]:remove()

local OriginColor = script.Parent.BrickColor

local JustRegened = false
local RegenWait = 5

Current = nil


local Allowance = 0 -- 0 = All, 1 = Group, 2 = GamePass.

local GroupId = 0
local GroupRank = 0
local GamePassId = 382612574

function CheckAllowed(plr)
	local ToReturn = false
	if Allowance == 0 then
		ToReturn = true
	elseif Allowance == 1 then
		if plr:IsInGroup(GroupId) and plr:GetRankInGroup(GroupId) >= GroupRank then
			ToReturn = true
		end
	elseif Allowance == 2 then
		if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr, GamePassId) == true then
			ToReturn = true
		end
	end
	return ToReturn
end

function Click(plr)
	if JustRegened == false then
	JustRegened = true
	script.Parent.BrickColor = BrickColor.new("Really black")
	coroutine.resume(coroutine.create(function()
	if plr then
		if plr.Character then
			if CheckAllowed(plr) == true then
			coroutine.resume(coroutine.create(function()
			if plr.Character:findFirstChild("SpeederVehicle") ~= nil then
				plr.Character["SpeederVehicle"]:remove()
			end
			end))
			for i, v in pairs(game.Players:GetChildren()) do
				coroutine.resume(coroutine.create(function()
				if v then
					if v.Character then
						if v.Character:findFirstChild("SpeederVehicle") then
							if (v.Character["SpeederVehicle"]["Speeder"]["Engine"].Position - script.Parent.Position).magnitude <= 10 then
								v.Character["SpeederVehicle"]:remove()
							end
						end
					end
				end
				end))
				wait(0.01)
			end
					local NewCloneModel = Instance.new("Model", plr.Character)
					NewCloneModel.Name = "SpeederVehicle"
					local NewClone = Cloned:clone()
					--NewClone.Parent = plr.Character
					NewClone.Parent = NewCloneModel
					end
				else
					local NewCloneValue = Instance.new("BoolValue", plr.Character)
					NewCloneValue.Name = "Vehicle"
					local NewClone2 = Cloned2:clone()
					NewClone2.Parent = NewCloneModel
				end
			if Allowance == 2 then
				game:GetService("MarketplaceService"):PromptPurchase(plr, GamePassId)
			end
		end
		end
		end)
	wait(RegenWait)
	JustRegened = false
	script.Parent.BrickColor = OriginColor
	end
end

script.Parent["ClickDetector"].MouseClick:connect(Click)

I am unsure of what to do, because the error is on line 81 but it says it’s trying to end the ‘(’ but line 41 ends with
coroutine.resume(coroutine.create(function()

Yeah, just add a bracket at the end that corresponds to that entire function. I don’t understand why it’s so hard to do that. Nothing wrong with the code, you just didn’t close one of the brackets.

2 Likes

Oh it’s not hard at all, finding which part is the problem is the hard part. Everytime I think I’ve found it, as soon as I fix it another red squiggle line just pops up. I’m not sure if I need to put a ‘)’ on the end of an end or somewhere else.

Nevermind, I’ve found it

1 Like

Next time, please don’t post on here until you cannot find any more answers.

2 Likes

In the future, I think proper indentation would have made the problem easier to see. You currently have three ends stacked at the same level of indentation, so it’s difficult to tell which end corresponds to which loop or function. Just something to keep in mind.

3 Likes

I didn’t know it worked like that, thank you for that tip. That would in-fact make things a lot easier.