Problem with end

Do i have to put another end or remove another?

local cost = 5
local titleVal = Instance.new("StringValue")
script.Parent.MouseButton1Click:Connect(function()

	local player = game.Players.LocalPlayer

	if player.leaderstats.Wins.Value >= cost then
		
		player.leaderstats.Wins.Value = player.leaderstats.Wins.Value - cost
		
		wait()
		script.Parent.Text = "Bought"
		titleVal.Name = script.Parent.Parent.Name
		titleVal.Parent = player.Inventory
	
		wait(0.1)
		script.Parent.Text = "Equip"
		
		print("You bought this title")
		
		script.Parent.MouseButton1Click:Connect(function()
			if script.Parent.Text == "Equip" then
			wait()
				script.Parent.Text = "Equipped"
				player.EquippedTitle.Value = script.Parent.Parent.Name
				if script.Parent.Text == "Equipped" then
					script.Parent.Text = "Unequipped"
					script.Parent.MouseButton1Click:Connect(function()
					if script.Parent.Text == "Unequipped" then
					wait()
					game.ReplicatedStorage.UnequipTitle:FireServer()
						
						script.Parent.Text = "Equip"	
						end
					end
				
			end --Expected to close line 28 got 'end'
		end
	end) 
1 Like

Your indentations are ruined, try to indent to make sure the code lines are inside the correct scope, this will lead you to whether your end’s are placed correctly or not.

You need to close this function with end) instead of end

You can check the output for this type of issues.

Also make sure to properly understand how to end each function and parenthesis.

end
end
end)
end
end)

this should be the correct sequence

You made a couple of mistakes in the end sequence as ShutzCh said. Be careful about functions and lining your lines of code properly. I took the liberty of fixing it, but use this as a future example:

local cost = 5
local titleVal = Instance.new("StringValue")
script.Parent.MouseButton1Click:Connect(function()
	local player = game.Players.LocalPlayer

	if player.leaderstats.Wins.Value >= cost then
		player.leaderstats.Wins.Value = player.leaderstats.Wins.Value - cost

		wait()
		script.Parent.Text = "Bought"
		titleVal.Name = script.Parent.Parent.Name
		titleVal.Parent = player.Inventory

		wait(0.1)
		script.Parent.Text = "Equip"

		print("You bought this title")

		script.Parent.MouseButton1Click:Connect(function()
			if script.Parent.Text == "Equip" then
				wait()
				script.Parent.Text = "Equipped"
				player.EquippedTitle.Value = script.Parent.Parent.Name
				if script.Parent.Text == "Equipped" then
					script.Parent.Text = "Unequipped"
					script.Parent.MouseButton1Click:Connect(function()
						if script.Parent.Text == "Unequipped" then
							wait()
							game.ReplicatedStorage.UnequipTitle:FireServer()
							script.Parent.Text = "Equip"	
						end
					end)
				end
			end
		end)
	end
end)