End Error On Scripts, How Do I Fix It?

Hello, I Have Encountered The Error With The End Lines A lot Of Times… I Just Encountered One Today And I Could Not Fix It, Please Help

game.Workspace.NoobRamsay.Head.ClickDetector.MouseClick:Connect(function(player)
player.PlayerGui.ShopGui.Enabled = true

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.ExitButton.MouseButton1Click:Connect(function()
	player.PlayerGui.ShopGui.Enabled = false
end)

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.L.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = true
	if player.leaderstats.Money.Value > 20 then
		player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
			player.PlayerGui.Confirmation.Enabled = false
		if player.leaderstats.Money.Value < 20 then

	player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
		player.PlayerGui.Confirmation.Enabled = false
	end)

	player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
		if not player.Backpack:findFirstChild('Lemonade') then
			local SwordClone = game.ReplicatedStorage.Lemonade:Clone()
			SwordClone.Parent = player.Backpack
			player.PlayerGui.Confirmation.Enabled = false

		else
			player.PlayerGui.Confirmation.Enabled = false
		end
	end)

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.B.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = true
	if player.leaderstats.Money.Value > 40 then
		player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
			player.PlayerGui.Confirmation.Enabled = false
	if player.leaderstats.Money.Value < 40 then

	player.PlayerGui.Confirmation.Frame.YesButton.MouseButton1Click:Connect(function()
		if not player.Backpack:findFirstChild('Egg') then
			local LongSwordClone = game.ReplicatedStorage.Egg:Clone()
			LongSwordClone.Parent = player.Backpack
			player.PlayerGui.Confirmation.Enabled = false
		else
			player.PlayerGui.Confirmation.Enabled = false
		end
		player.PlayerGui.ShopGui.MainFrame.ButtonFrame.C.MouseButton1Click:Connect(function()
			player.PlayerGui.Confirmation.Enabled = true
					if player.leaderstats.Money.Value > 80 then
						player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
							player.PlayerGui.Confirmation.Enabled = false
					if player.leaderstats.Money.Value < 80 then

			player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
				player.PlayerGui.Confirmation.Enabled = false
													end)
													end
			player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
				if not player.Backpack:findFirstChild('Cheeseburger') then
					local SwordClone = game.ReplicatedStorage.Cheeseburger:Clone()
					SwordClone.Parent = player.Backpack
					player.PlayerGui.Confirmation.Enabled = false

				else
					player.PlayerGui.Confirmation.Enabled = false
				end
											end)
										end
									end)
								end
	end)
						end)
					end
			end)
	end

Error:

ServerScriptService.ShopScript:67: Expected ‘)’ (to close ‘(’ at line 48), got ‘end’

1 Like

Basically, for every “then” or “function” there needs to be an “end”. And for every opening “(” or “[” there needs to be a closing “)” or “]”.

The reason you are having this issue because you have connections inside connections inside connections which can get really confusing. Generally you would want all connections to be standalone meaning they are not inside another connection. Then those connections would check for conditions before they run.

4 Likes

So I Have To Add An End After Every “then” function or something?

2 Likes

Try to count and close each opening. Do not spam ends everywhere without reason.

2 Likes

Alright Thanks, So I Will Add An End After Every Function, “(” and “then”?

1 Like

I recommend to follow this advice:

2 Likes

i cant really get it settled aswell, i tried some endings after every function “(” and “then”

1 Like

Normal function:

local function blah()
-- stuff
end

Normal connection:

part.Touched:Connect(function()
-- blah
end)

Notice because the function for the connection is inside connect() which is why the “end” has a “)” after it.

2 Likes

Oh Thanks! Ill Try it Now :DDDDDDD

1 Like

Thank you so much, It Works Just As Supposed!

1 Like
player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = false
end)

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.ExitButton.MouseButton1Click:Connect(function()
	player.PlayerGui.ShopGui.Enabled = false
end)

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.L.MouseButton1Click:Connect(function()
	if player.leaderstats.Money.Value > 20 then
		--do stuff
	end
end)

player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = false
	if player.leaderstats.Money.Value < 20 then
		--do stuff
	end
end)

player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
	if not player.Backpack:findFirstChild('Lemonade') then
		local SwordClone = game.ReplicatedStorage.Lemonade:Clone()
		SwordClone.Parent = player.Backpack
		player.PlayerGui.Confirmation.Enabled = false
	else
		player.PlayerGui.Confirmation.Enabled = false
	end
end)

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.B.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = true
	if player.leaderstats.Money.Value > 40 then
		--do stuff
	end
end)

player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = false
	if player.leaderstats.Money.Value < 40 then
	--do stuff
	end
end)

player.PlayerGui.Confirmation.Frame.YesButton.MouseButton1Click:Connect(function()
	if not player.Backpack:findFirstChild('Egg') then
		local LongSwordClone = game.ReplicatedStorage.Egg:Clone()
		LongSwordClone.Parent = player.Backpack
		player.PlayerGui.Confirmation.Enabled = false
	else
		player.PlayerGui.Confirmation.Enabled = false
	end
end)

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.C.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = true
	if player.leaderstats.Money.Value > 80 then
		--do stuff
	end
end)

player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = false
	if player.leaderstats.Money.Value < 80 then
		--do stuff
	end
end)

player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
	if not player.Backpack:findFirstChild('Cheeseburger') then
		local SwordClone = game.ReplicatedStorage.Cheeseburger:Clone()
		SwordClone.Parent = player.Backpack
		player.PlayerGui.Confirmation.Enabled = false
	else
		player.PlayerGui.Confirmation.Enabled = false
	end
end)

I made an effort to clean everything up, you’ll need to fix how everything is arranged.

3 Likes
player.PlayerGui.ShopGui.MainFrame.ButtonFrame.C.MouseButton1Click:Connect(function()
	player.PlayerGui.Confirmation.Enabled = true
	if player.leaderstats.Money.Value > 20 then
		player.PlayerGui.Confirmation.Enabled = true
		player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
			if not player.Backpack:findFirstChild('Lemonade') then
				local SwordClone = game.ReplicatedStorage.Lemonade:Clone()
				SwordClone.Parent = player.Backpack
				player.PlayerGui.Confirmation.Enabled = false
			else
				player.PlayerGui.Confirmation.Enabled = false
			end
		end)
		player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
			player.PlayerGui.Confirmation.Enabled = false
		end)
	
	elseif player.leaderstats.Money.Value > 40 then
		player.PlayerGui.Confirmation.Enabled = true
		player.PlayerGui.Confirmation.Frame.YesButton.MouseButton1Click:Connect(function()
			if not player.Backpack:findFirstChild('Egg') then
				local LongSwordClone = game.ReplicatedStorage.Egg:Clone()
				LongSwordClone.Parent = player.Backpack
				player.PlayerGui.Confirmation.Enabled = false
			else
				player.PlayerGui.Confirmation.Enabled = false
			end
		end)
		player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
			player.PlayerGui.Confirmation.Enabled = false
		end)
		
	elseif player.leaderstats.Money.Value > 80 then
		player.PlayerGui.Confirmation.Enabled = true
		player.PlayerGui.Confirmation.Frame.Accept.MouseButton1Click:Connect(function()
			if not player.Backpack:findFirstChild('Cheeseburger') then
				local SwordClone = game.ReplicatedStorage.Cheeseburger:Clone()
				SwordClone.Parent = player.Backpack
				player.PlayerGui.Confirmation.Enabled = false
			else
				player.PlayerGui.Confirmation.Enabled = false
			end
		end)
		player.PlayerGui.Confirmation.Frame.Cancel.MouseButton1Click:Connect(function()
			player.PlayerGui.Confirmation.Enabled = false
		end)
		
	else
		player.PlayerGui.Confirmation.Enabled = false
	end
end)

player.PlayerGui.ShopGui.MainFrame.ButtonFrame.ExitButton.MouseButton1Click:Connect(function()
	player.PlayerGui.ShopGui.Enabled = false
end)
2 Likes

Thank You!, I Had Problems With The Value And This Is What I’ve Been Looking For, Thanks!

1 Like

Welp Just Encountered Another problem…

ServerScriptService.ShopScript:2: attempt to index nil with ‘PlayerGui’

1 Like

Yeah, you need to define the player (you didn’t in the originally provided script). If this is a local script then you can just use “game.Players.LocalPlayer”.

2 Likes

I Mean Its An Server Script, I Tried Adding An Variable But Didnt Work

1 Like

i tried alot of things… nothing seems to be working. variables, game:WaitForChild(“Players”) etc…

1 Like

Send me the game file so I can see what you’re trying to achieve and go from there, feel free to send me a message.

1 Like

If I Explain It, It Would Be Alot Easier. So What Im trying To Make Is an NPC tool giver which cost’s money (intval), the gui is in starter gui and it gives
The error i mentioned earlier, the reason i dont wanna share the game file is because its kinda an private project

1 Like

Tell me if you need further details :slight_smile:

1 Like